Net-informations.com
SiteMap  | About    

$.map Vs. $.grep in jQuery



The difference is that the grep() method filters an array and returns the filtered array, while map() method applies a function to each item in the array, thus returning a modified array.

jQuery map() method

The map() function translates a set of elements in the jQuery object into another set of values in a jQuery array which may, or may not contain elements.

In the above code will return 20 and 30.

run this source code Try it Yourself

Full Source

jQuery grep() method

The jQuery grep() method is used to filter the contents of an array.

In the above code willreturn 20 and 30.

run this source code Try it Yourself

Full Source

So, we can see here the difference is grep() method filters an array and returns the filtered array, while map() method applies a function to each item in the array, thus returning a modified array.










net-informations.com (C) 2019    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.