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


Please Help Members By Posting Answers For Below Questions

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?

864


How can jquery library be added to pages?

952


How to always reference latest version of jquery?

875


How do you install/use jquery in a project. What is the minimum setup needed to start using jquery.

999


What is the minimum setup needed to start using jquery.

939


How to validate email using jquery?

975