0👍
You are looking for this (in JS ES6):
Object.values(yourObject).filter(item => typeof item === 'number').reduce((a,b) => a+b)
Explanation:
Object.values()
selects all the values of your object.filter()
filters your values so only numbers remain.reduce()
loops through the array and adds all the members together
A good article on the ES6 stuff:
https://medium.com/poka-techblog/simplify-your-javascript-use-map-reduce-and-filter-bd02c593cc2d
Object.values explanation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Object/values
- [Vuejs]-.save is not a function, and .findOneAndUpdate() doesn't update my db
- [Vuejs]-VueJS – Using 'this' in a callback function
Source:stackexchange.com