To total an array, a loop can keep a running sum. With JavaScript’s reduce method, that running value is the accumulator: the intermediate result carried from one array item to the next. section 10.1.4
Listing 10.10 Aggregating items with reduce
const numbers = [1, 2, 3, 4]; const sum = numbers.reduce( #A (acc, number) => acc + number, #A 0, #A ); #A console.assert(sum === 10, "The sum of all numbers is 10");
The initial accumulator is 0. For each number, the callback returns a new sum; after the last number, reduce returns 10. section 10.1.4
An accumulator need not be a number. It can be an object, map, buffer, or other value built from the array. A loop may be clearer for a simple sum, but understanding reduce helps when you encounter it in existing code. section 10.1.4






