Answers for "get sum of a key in array of objects javascript"

5

javascript sum array values by key

var array = [
  {name: "Peter", age: 43},
  {name: "John", age: 32},
  {name: "Jake", age: 21}
];

array.reduce(function(sum, current) {
  return sum + current.age;
}, 0); // 43 + 32 + 21 = 96
Posted by: Guest on May-22-2020
10

javascript sum array of objects

arr = [{x:1}, {x:3}]

arr.reduce((accumulator, current) => accumulator + current.x, 0);
Posted by: Guest on April-29-2020

Code answers related to "get sum of a key in array of objects javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language