1

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?

0

2 Answers 2

1

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

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

}
Sign up to request clarification or add additional context in comments.

Comments

0

Another simple way that doesn't require mapping is using Object.values():

const obj = {
  collectedTrashCount: 139,
  dangerousAreaCount: 11,
  schoolCount: 5,
  trashBinCount: 44,
}
const values = Object.values(obj)
console.log(values)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.