reduce()
Reduces the array to a single value.
Syntax
arr.reduce((total, e) => ..., start)
Description
Accumulates elements into a single result (total, product, maximum...). The second argument is the initial value.
Returns
A single value.
Example
Loading editor…
Expected output
10
When to use?
Sum, average, cart total, count.