How to sum a property in an array of objects with JavaScript

1 Answer

0 votes
const arr = [
  {id: 509, score: 85},
  {id: 982, score: 91},
  {id: 452, score: 93},
  {id: 344, score: 100},
];

const sum = arr.reduce((val, object) => val + object.score, 0);

console.log(sum); 
  
  
  
    
      
      
/*
run:
      
369
      
*/

 



answered Jun 29, 2022 by avibootz
...