+ 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 😅
42 Answers
+ 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
+ 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'
+ 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" ]
+ 15
$hardul B
You can watch this video tut also
https://youtu.be/rRgD1yVwIvE
+ 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
+ 13
$hardul B 💪Yeah! 🍻
It's my pleasure friend! 😆
Keep coding!👍
+ 12
https://youtu.be/rRgD1yVwIvE
See This is helpful Bro
+ 12
$hardul B 👍
You are very welcome!😊
+ 12
$hardul B 😄...😃👍🍻
+ 12
Catch these funny examples🤓
https://medium.com/@js_tut/map-filter-and-reduce-animated-7fe391a35a47
+ 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
+ 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/
+ 8
By - Charan Leo25ㅤㅤㅤㅤㅤㅤㅤㅤ it is a respect for response as an acknowledgement...
+ 8
Thank you 4rontender
+ 7
Thank you for answering Danijel Ivanović
ᐺ ! ᖇ † ᒪ
+ 7
That's really useful Danijel Ivanović
😃😃
+ 7
filter() function manipulates tha same list as per the condition while map() returns a new list as per the condition
+ 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.
+ 5
OK will have a look at it... 😅 Thanks Shubham Verma