Answers for "javascript total sum of array of objects reduce"

17

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
0

javascript reduce function to get sum of object value

javascript reduce function to get sum of specific object property 

let records = [
  {name: 'ball',amount: 20},
  {name: 'toy',amount: 40},
  {name: 'book',amount: 30}
]

const amount = records.reduce((acc, cv) => {
    return acc + cv.amount;
  }, 0);

// amount = 90
Posted by: Guest on May-02-2022

Code answers related to "javascript total sum of array of objects reduce"

Code answers related to "Javascript"

Browse Popular Code Answers by Language