Learn JavaScript
Advanced Array Methods
31.23
Lesson

reduce()

The reduce() method executes a function on each element of the array. It returns a single value.

The reduce() method can accept four arguments -

  • The accumulator stores the value returned from the previous function call.

  • The currentValue is the value of the current element in the array.

  • The currentIndex is the index of the current element in the array.

  • The sourceArray is the array.


We can provide an optional initial value. The accumulator takes this value.

If we do not provide it, the function takes the first element of the array as the initial value.