[Vuejs]-VueJS sum up all number values in data row

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

Leave a comment