DEV Community

Discussion on: Array.reduce() for newbies

Collapse
 
alejandroxx002 profile image
AlejandroXX002

Great article, the examples are super friendly, just one question. Why the starting value for the the accumulator is 0 in both cases?

Collapse
 
papaponmx profile image
Jaime Rios

Hi, thanks for the kind words.

The reason why I set the initial value to 0 is because I want to get a number from array.reduce.

Notice that the value for the accumulator could be anything like and array, an empty object, a boolean or a string.