Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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
 
PREVIOUS NEXT
Tagged: #javascript #reduce #function #sum #object
ADD COMMENT
Topic
Name
4+5 =