How to sum the numbers in an array with Node.js

2 Answers

0 votes
const arr = [6, 8, 1, 2, 5, 9, 7, 3];
  
const sum = arr.reduce((x, y) => x + y);

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

 



answered Jun 29, 2022 by avibootz
0 votes
const arr = [6, 8, 1, 2, 5, 9, 7, 3];
  
let sum = 0;
 
for (let num of arr) {
    sum = sum + num
}
  
console.log(sum); 
  
  
  
    
      
      
/*
run:
      
41
      
*/

 



answered Jun 29, 2022 by avibootz

Related questions

1 answer 97 views
1 answer 121 views
1 answer 134 views
...