JavaScriptArrayreduce

Executes a reducer function on each element, resulting in a single output value.

Syntax

arr.reduce(callbackFn, initialValue?)

Example

Enter values below to update the example in real time.

const
numbers
reduce
acc
cur
console
const numbers = [1, 2, 3, 4, 5];
const sum = numbers.reduce((acc, cur) => acc + cur, 0);
console.log(sum);   // 15