Understanding Array.reduce() for Accumulating Values in Javascript


Accumulate a single value from an array.

Source Code

let numbers = [1, 2, 3, 4];
let sum = numbers.reduce(function(accumulator, currentValue) {
  return accumulator + currentValue;
}, 0);
console.log(sum); // 10
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments