How to sum a property in an array of objects with Node.js

1 Answer

0 votes
const arr = [
  {id: 609, score: 80},
  {id: 782, score: 81},
  {id: 552, score: 84},
  {id: 544, score: 97},
];
 
const sum = arr.reduce((val, object) => val + object.score, 0);
 
console.log(sum); 
   
   
   
     
       
       
/*
run:
       
342
       
*/

 



answered Jun 29, 2022 by avibootz

Related questions

...