Skip to main content
Code and think

Javascript Array Reduce

Reduce will return the first element when array has only one element and no initial value is passed.

If the array only has one element (regardless of position) and no initialValue is provided, or if initialValue is provided but the array is empty, the solo value will be returned without calling callbackFn.

Keep in mind that it does not call the callback. This can lead to some surprises when using array of objects :)

Reference