Using Array.reduce to Sum Values in Javascript


reduce can be used to sum up numbers in an array.

Source Code

let numbers = [1, 2, 3, 4, 5];
let sum = numbers.reduce((acc, current) => acc + current, 0);
console.log(sum);
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments