# .map and .filter methods confusion with return statement javascript

**URL:** <https://forum.kirupa.com/t/map-and-filter-methods-confusion-with-return-statement-javascript/642981>\
**Category:** programming\
**Created:** [May 26, 2020, 2:05pm UTC](https://forum.kirupa.com/t/map-and-filter-methods-confusion-with-return-statement-javascript/642981 "2020-05-26T14:05:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Umair\_Ashraf](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/umair_ashraf/32/11705_2.png) [@Umair\_Ashraf](https://forum.kirupa.com/u/Umair_Ashraf)\
**Post date:** [May 26, 2020, 2:05pm UTC](https://forum.kirupa.com/t/map-and-filter-methods-confusion-with-return-statement-javascript/642981/1 "2020-05-26T14:05:22Z")

</div>

Hi Guys,  
I am a bit struggling with the return for the below two scenarios, using .map and .filter functions.  
why the return statement when using the .filter methods return the items in the items array rather then bollian (true or false) as the return is ( item.split(’’).reverse().join(’’) === item;) which if i return correctly, says it will return the comparision between two items.  
really appreciate if someone can clarify me the below concept.

```javascript
////////////using Map///////////////
var items = ['mum', 'dad', 'brother'];
items.map(function(item) {
  return item.split('').reverse().join('') === item;
});

// returns [true, true, false]
///////////////////////////////////////

```

```javascript
//////////////using Filter////////////////
var items = ['mum', 'dad', 'brother'];
items.filter(function(item) {
  return item.split('').reverse().join('') === item;
});

// returns ['mum', dad']
//////////////////////////////////////////////

```

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [May 26, 2020, 2:57pm UTC](https://forum.kirupa.com/t/map-and-filter-methods-confusion-with-return-statement-javascript/642981/2 "2020-05-26T14:57:07Z")

</div>

That’s what filter does, it returns the original items based on the return value inside the callback. If the callback returns true for that iteration in the looping, the item is kept in the result. If it returns false, the item is removed from the result - the result that represents a “filtered” version of the original array - the same values, just some may have been removed.

`map` on the other hand changes values. Same number of values, but the values change depending on the return values of the callback function. Map doesn’t remove values like filter does, only changes them. Filter doesn’t change values like map does, only removes them.

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [May 26, 2020, 5:07pm UTC](https://forum.kirupa.com/t/map-and-filter-methods-confusion-with-return-statement-javascript/642981/3 "2020-05-26T17:07:20Z")

</div>

> [@senocular](#):
>
> Map doesn’t remove values like filter does, only changes them. Filter doesn’t change values like map does, only removes them.

This could be part of a nursery rhyme for kids! Sounds similar to [Goosey Gander](https://en.wikipedia.org/wiki/Goosey_Goosey_Gander).

Ok, I’ll leave now.

😛
