4👍
In ES6 you can do it as follows.
const objectValueSum = (obj) =>
Object.keys(obj)
.map(food => obj[food])
.reduce((a, b) => a + b);
const sum = objectValueSum(this.data.food.monday);
Object.keys
returns the object keysmap
returns an array of the amountsreduce
sums up all the amounts
Don’t forget to use Babel or Traceur for transpiling to ES5.
👤str
- [Vuejs]-VueJS not rendering component on jquery ajax load
- [Vuejs]-Vue.js When input elements are present, strange error appears in console
Source:stackexchange.com