Which JavaScript array method executes a reducer function on each element, resulting in a single output value?

The story behind the answer

The JavaScript array method that applies a reducer function and produces one accumulated result is `reduce`.

Called as `array.reduce(callback, initialValue)`, the method processes array elements in order and passes the callback’s return value into the next call as the accumulator. This lets one array become a sum, product, object, string, flattened array, or another single value. For example, a reducer can add each number to a running total.

Providing an initial value is usually the clearest and safest approach. If it is omitted, the first array element becomes the initial accumulator and iteration begins with the second element. Calling `reduce()` on an empty array without an initial value throws a `TypeError`; an empty array with an initial value returns that initial value without invoking the callback.

`map()` transforms elements while preserving an array-shaped result, `filter()` selects elements into an array, and `forEach()` performs an action without producing a useful accumulated return value. JavaScript also provides `reduceRight()`, which processes elements from right to left.

Source: Wikipedia · fact-checked Sept. 2026

Add question to a list

Choose a list to keep this question in: