+ 26

What is the difference between 'map()' and 'filter()' methods in JavaScript?

What I know is both of them execute a function for every element in array and return a new array in response to it(i.e not affect the original array). So what exactly is the difference between both of them.. https://www.sololearn.com/Discuss/1818527/?ref=app I referred this question..I know It's for Python.. Well it didn't help me much 😅

2nd Jul 2019, 11:54 AM
$hardul B
$hardul B - avatar
42 Réponses
+ 16
$hardul B Check this.Out!😉 • JavaScript’s Filter Function Explained By Applying To College — https://dev.to/kbk0125/javascripts-filter-function-explained-by-applying-to-college-58j0
3rd Jul 2019, 6:06 AM
Danijel Ivanović
Danijel Ivanović - avatar
+ 19
• map() is key method of an array when it comes to thinking in functional programming terms. Given an array, we can use map() to create a new array from the initial one, and then filtering the result using filter(). For example, We creating a new array to get the first letter of each item in the list array, and filters the one that matches A : const list = [ 'Apple', 'Orange', 'Egg' ] list.map( item => item[0] ) .filter( item => item === 'A' ) // 'A'
2nd Jul 2019, 4:53 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 18
• filter() is a very important method of an array. A good example of using filter() is when you want to remove an item from the array : const items = [ 'a', 'b', 'c', 'd', 'e', 'f' ] const valueToRemove = 'c' const filteredItems = items.filter( item => item !== valueToRemove ) // [ "a", "b", "d", "e", "f" ]
2nd Jul 2019, 4:58 PM
Danijel Ivanović
Danijel Ivanović - avatar
2nd Aug 2019, 9:27 AM
Вап
+ 15
$hardul B You can watch this video tut also https://youtu.be/rRgD1yVwIvE
2nd Aug 2019, 9:39 AM
Вап
+ 14
$hardul B 😆 [ Simplify your JavaScript: ]👍 Use .map(), .reduce(), and .filter() – https://medium.com/poka-techblog/simplify-your-javascript-use-map-reduce-and-filter-bd02c593cc2d
2nd Aug 2019, 8:55 AM
Danijel Ivanović
Danijel Ivanović - avatar
+ 13
$hardul B 💪Yeah! 🍻 It's my pleasure friend! 😆 Keep coding!👍
2nd Aug 2019, 11:08 AM
Danijel Ivanović
Danijel Ivanović - avatar
+ 12
https://youtu.be/rRgD1yVwIvE See This is helpful Bro
2nd Jul 2019, 11:57 AM
Shubham Kumar
+ 12
$hardul B 👍 You are very welcome!😊
3rd Jul 2019, 4:35 AM
Danijel Ivanović
Danijel Ivanović - avatar
+ 12
$hardul B 😄...😃👍🍻
3rd Jul 2019, 6:30 AM
Danijel Ivanović
Danijel Ivanović - avatar
19th Jul 2019, 2:49 PM
Вап
+ 9
filter() && map() methods are not similar they are too different... 1. Array.prototype.filter.call() https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter 2.Array.prototype.map.call() https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
2nd Jul 2019, 12:00 PM
Basel.Al_hajeri?.MBH()
Basel.Al_hajeri?.MBH() - avatar
+ 9
An Illustrated (and Musical) Guide to Map, Reduce, and Filter Array Methods https://css-tricks.com/an-illustrated-and-musical-guide-to-map-reduce-and-filter-array-methods/
3rd Jul 2019, 6:24 AM
Вап
+ 8
By - Charan Leo25ㅤㅤㅤㅤㅤㅤㅤㅤ it is a respect for response as an acknowledgement...
2nd Jul 2019, 3:14 PM
BroFar
BroFar - avatar
+ 8
Thank you 4rontender
3rd Jul 2019, 8:23 AM
$hardul B
$hardul B - avatar
+ 7
Thank you for answering Danijel Ivanović ᐺ ! ᖇ † ᒪ
3rd Jul 2019, 4:24 AM
$hardul B
$hardul B - avatar
+ 7
That's really useful Danijel Ivanović 😃😃
3rd Jul 2019, 6:11 AM
$hardul B
$hardul B - avatar
+ 7
filter() function manipulates tha same list as per the condition while map() returns a new list as per the condition
6th Jul 2019, 4:15 AM
Khushi Gupta
Khushi Gupta - avatar
+ 6
By - Charan Leo25ㅤㅤㅤㅤㅤㅤㅤㅤ this is his choice and his way as this is his thread... please let's stay relevant to topic as he seeks the differences between filters() as garbage in garbage out and map() a clear course for him to follow.
2nd Jul 2019, 3:54 PM
BroFar
BroFar - avatar
+ 5
OK will have a look at it... 😅 Thanks Shubham Verma
2nd Jul 2019, 11:58 AM
$hardul B
$hardul B - avatar