adspace
What is the difference between $.map and $.grep in jQuery?
Answer Posted / Omprakash Das
Both $.map() and $.grep() are functions provided by jQuery to manipulate arrays. However, they have different use cases:n
1. $.map(): It takes a function as an argument which is applied to each element of the array, and returns a new array with the results.
2. $.grep(): It also takes a function but instead of returning a new array, it filters the elements in the original array that match the provided condition.nnFor example:n$.map([1, 2, 3], function(value) { return value * 2; }) returns [2, 4, 6]n$.grep([1, 2, 3], function(value) { return value > 2; }) returns [3]
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Do you have plans for a new jquery plug-in or something else we should look out for? Where to from here for the imgpreview plugin?
How can jquery library be added to pages?
How to always reference latest version of jquery?
How do you install/use jquery in a project. What is the minimum setup needed to start using jquery.
What is the minimum setup needed to start using jquery.
How to validate email using jquery?