---
title: "Discussion on \"Use JavaScript reduce function for more than sum\" | Hashnode"
description: "Discussion on \"Use JavaScript reduce function for more than sum\". When I say there is a lot more you can do with reduce function you wont believe me .Trust me before I started to put this article together I also did not know that this many things can be possible .\nMost of you would already be familiar with the simp..."
url: "https://hashnode.com/posts/use-javascript-reduce-function-for-more-than-sum/602cd60f2d9e060f1cee6b2a"
---

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

Discussion

# [Use JavaScript reduce function for more than sum](https://yatheesh.hashnode.dev/use-javascript-reduce-function-for-more-than-sum?utm_source=hashnode&utm_medium=feed)

When I say there is a lot more you can do with reduce function you wont believe me .Trust me before I started to put this article together I also did not know that this many things can be possible . Most of you would already be familiar with the simp...

Feb 17, 2021 · 5 min read · yatheesh.hashnode.dev  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)
-   [#functions](https://hashnode.com/tag/functions)
-   [#web-development](https://hashnode.com/tag/web-development)
-   [#array-methods](https://hashnode.com/tag/array-methods)

## Written by

[Yatheesh](https://hashnode.com/@yatheesh)

@yatheesh · India

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

Engineer . Web Developer and more .

## Responses 1

Markdown supported · ⌘↵ to post

[Chaku](https://hashnode.com/@chakudi)

[Feb 18, 2021](https://hashnode.com/posts/use-javascript-reduce-function-for-more-than-sum/602cd60f2d9e060f1cee6b2a/comment/602dcdca094669172f4d0c0f)

Thanks for sharing these examples. I definitely leaned new thing today.

You could also use reduce method to flatten an array, but I don't exactly know how!

[Yatheesh](https://hashnode.com/@yatheesh)

[Feb 18, 2021](https://hashnode.com/posts/use-javascript-reduce-function-for-more-than-sum/602cd60f2d9e060f1cee6b2a/comment/602dcdca094669172f4d0c0f#reply-602e0ae7797c7f1cb42b1da0)

Flattening an array is nothing but returning only selected items in the form of array . we can push only the needed value instead of the item . see the example below

```
const utubers=[{id:1,name:'Test Ed',sal:5000},{id:2,name:'Dev Ed',sal:5000},{id:3,name:'Mr Beast',sal:2000},{id:4,name:'Mr Boss',sal:2000},{id:5,name:'MKBHD',sal:5000}]

const salGt2000ids = utubers.reduce(((tempArray,utuber)=>{
// get an array with only whose sal is more than 2000 
if(utuber.sal>2000){
tempArray.push(utuber.id)
}
return tempArray;
}
),[])
console.log(salGt2000ids);
//[1, 2, 5]
```
