JavaScript · Arrays

reduce

Folds an array into a single value. Always pass an initial value when the type matters.

Syntax
items.reduce((acc, item) => acc + item, 0)

Example

Try it

More in this group

array.at() array.concat() array.fill() array.findIndex() array.findLast() array.flat() array.flatMap() array.forEach()

Learn this in the course

Reference pages are the quick answer. The course explains the why, shows the full example and ends with a challenge.

Open the course