Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
295 views
in Technique[技术] by (71.8m points)

arrays - Javascript / Vue JS - Retrieve value of all elements in object

I have an object that retrieves 4 different elements with different numerical values. I'm trying to access and retrieve all these numerical values.

The object returns the following:

{__ob__: Observer}
  collectedTrashCount: 139
  dangerousAreaCount: 11
  schoolCount: 5
  trashBinCount: 44

If I want to retrieve the value of the collectedTrashCount, I would simply do the following:

computed: {
    dashboardList: function () {
      return this.$store.getters.getDashboard;
    },
    checkCount: function () {
      console.log(this.dashboardList.collectedTrashCount);
    }
  },

The console.log in this case would give me 139.

My question is: What should I do to return all these values such as: 139, 11, 5, 44?

question from:https://stackoverflow.com/questions/65843919/javascript-vue-js-retrieve-value-of-all-elements-in-object

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You could use entries method to map that values in an array :

checkCount: function () {
   return Object.entries(this.dashboardList).map(([key, val]) => val)

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...