---
title: "Comment by Chaku on \"Use JavaScript reduce function for more than sum\" | Hashnode"
description: "Thanks for sharing these examples. I definitely leaned new thing today. You could also use reduce method to flatten an array, but I don&#39;t exactly know how!"
url: "https://hashnode.com/posts/use-javascript-reduce-function-for-more-than-sum/602cd60f2d9e060f1cee6b2a/comment/602dcdca094669172f4d0c0f"
---

[Discussion](https://hashnode.com/posts/use-javascript-reduce-function-for-more-than-sum/602cd60f2d9e060f1cee6b2a)

Comment [Use JavaScript reduce function for more than sum](https://hashnode.com/posts/use-javascript-reduce-function-for-more-than-sum/602cd60f2d9e060f1cee6b2a)

[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]
```
