---
title: "Discussion on \"Basics Of JavaScript Reduce() Method\" | Hashnode"
description: "Discussion on \"Basics Of JavaScript Reduce() Method\". The reduce() method is one of Javascript's array method. As a JavaScript developer, the reduce() method comes in handy when working with arrays.\nIn this article, I would try my best to explain the basics behind the reduce() method and how it works.\nL..."
url: "https://hashnode.com/posts/basics-of-javascript-reduce-method/5f2d4cb3b8ac395b1f23a08e"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Basics Of JavaScript Reduce() Method](https://barnabas.hashnode.dev/basics-of-javascript-reduce-method?utm_source=hashnode&utm_medium=feed)

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...

Aug 7, 2020 · 4 min read · barnabas.hashnode.dev  
Read the article

## Written by

[Barnabas Asha](https://hashnode.com/@Barnabas)

@Barnabas · Lagos, Nigeria

  
[View profile](https://hashnode.com/@Barnabas)

Frontend developer

## Responses 5

Markdown supported · ⌘↵ to post

[Amarachi Johnson](https://hashnode.com/@amarachukwu)

[Aug 11, 2020](https://hashnode.com/posts/basics-of-javascript-reduce-method/5f2d4cb3b8ac395b1f23a08e/comment/5f3235712a23d9080d1794d1)

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 `150`

I 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 `140` instead of `150`?

[Barnabas Asha](https://hashnode.com/@Barnabas)

[Aug 11, 2020](https://hashnode.com/posts/basics-of-javascript-reduce-method/5f2d4cb3b8ac395b1f23a08e/comment/5f3235712a23d9080d1794d1#reply-5f323b1f4332ee07eb55c22e)

I'm glad you liked the article, In the case where an initial value is not specified the reducer starts from index 1 and the first member of the array (index 0) is taken as the accumulator for the first execution.

```
arr = [10, 20, 30, 40, 50]
callback = function (acc, cur) {
return acc + cur
}

arr.reduce(callback)

/* first instance: 10 is taken as the initial val since one isn't specified and used as the accumulator 
So the callback returns */

return 10 + 20

/* Then 30 becomes the accumulator for the next execution. And it goes on */
```

I hope I was able to shed more light and not confuse you. Feel free to reach me.

[Edidiong Asikpo (Didi)](https://hashnode.com/@didicodes)

[Aug 9, 2020](https://hashnode.com/posts/basics-of-javascript-reduce-method/5f2d4cb3b8ac395b1f23a08e/comment/5f3079113348367b2fc3f8dc)

This is really amazing for a first article [Barnabas Asha](https://hashnode.com/@Barnabas). Keep up the good work. I can't wait to read your next article.

[Barnabas Asha](https://hashnode.com/@Barnabas)

[Aug 9, 2020](https://hashnode.com/posts/basics-of-javascript-reduce-method/5f2d4cb3b8ac395b1f23a08e/comment/5f3079113348367b2fc3f8dc#reply-5f3080ae3348367b2fc3f8ef)

Thank you Didi

[Temi Ogundeji](https://hashnode.com/@Temiogundeji)

[Aug 7, 2020](https://hashnode.com/posts/basics-of-javascript-reduce-method/5f2d4cb3b8ac395b1f23a08e/comment/5f2d563b3b12e25afe3e4797)

Nice article bro! Keep it up.

[Barnabas Asha](https://hashnode.com/@Barnabas)

[Aug 7, 2020](https://hashnode.com/posts/basics-of-javascript-reduce-method/5f2d4cb3b8ac395b1f23a08e/comment/5f2d563b3b12e25afe3e4797#reply-5f2dbc4bb8ac395b1f23a3d6)

Thanks boss

[Nwafor Uchechukwu](https://hashnode.com/@Webdot_30)

[Aug 7, 2020](https://hashnode.com/posts/basics-of-javascript-reduce-method/5f2d4cb3b8ac395b1f23a08e/comment/5f2d55483b12e25afe3e4787)

Nice article 👍

[Barnabas Asha](https://hashnode.com/@Barnabas)

[Aug 7, 2020](https://hashnode.com/posts/basics-of-javascript-reduce-method/5f2d4cb3b8ac395b1f23a08e/comment/5f2d55483b12e25afe3e4787#reply-5f2dbc533b12e25afe3e4aa0)

Thanks man
