How to sum all the values in an array in JavaScript

1 Answer

0 votes
const arr = [6, 8, 1, 2, 5];
 
let sum = arr.reduce((x, y) => x + y);
 
console.log(sum); 
 
 
 
   
     
     
/*
run:
     
22
     
*/

 



answered Feb 15, 2021 by avibootz
edited Jun 4, 2021 by avibootz
...