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

1 Answer

0 votes
const arr = [
  {id: 209, score: 75},
  {id: 182, score: 81},
  {id: 852, score: 83},
  {id: 144, score: 92},
];

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

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

 



answered Jun 29, 2022 by avibootz
...