The reduce() method is one of Javascript's array method. As a JavaScript developer, the reduce() method comes in handy when working with arrays. In this article, I would try my best to explain the basics behind the reduce() method and how it works. L...

Markdown supported · ⌘↵ to post
Amarachi Johnson
This is really amazing for a first article Barnabas Asha. Keep up the good work. I can't wait to read your next article.
Coincidentally, I googled about the reduce method just last night, so waking up to this well explained article already made my day. Thanks for breaking down this topic.
I have a question though. In the 2nd example you gave were we had
const arr = [10, 20, 30, 40, 50] const arrSum = arr.reduce((acc, curr) => { return acc + curr })You said the output was going to be
150I find this quite confusing since you also stated that if an initial value is not stated just as above, the reducer starts from index 1 which in this case is 20.
So shouldn't the result be
140instead of150?