As written in documentation the reduce() method applies a function against an accumulator and each value of the array (from left-to-right) to reduce it to a single value.
(M) a callback reducer function to be applied that deals with a pair of previous (result of previous computation) and next element until end of the list.
(O) an initial value to be used as the first argument to the first call of the callback.
So let's see a common usage and later a more sophisticated one.
We are on Amazon website (prices in $) and our caddy is quite full, let's compute total.
Optional reduce function parameter was primitive integer type 0 in that first case, but it could have been an Object, an Array…instead of a primitive type, but we will see that later.
Now, cool I received a discount coupon of 20$.
This second usage example is inspired by Redux combineReducers function source.
Idea behind is to separate reducer function into separate individual functions and at the end compute a new single big reducer function.
responsible for applying each partial reduce functions.
Now let's see how using it.
I hope this approach can give you another idea of using reduce() function for your own needs.