What is the difference between $.map and $.grep in jQuery?



What is the difference between $.map and $.grep in jQuery?..

Answer / 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

More jQuery Interview Questions

What is .remove()? : jquery mobile

1 Answers  


How to run an event handler only once in jQuery?

1 Answers  


What is a CDN?

1 Answers  


What is jquery mobile theming? : jquery mobile

1 Answers  


You get "jquery is not defined" or "$ is not defined" error. What could be the reason?

1 Answers  


Whether jQuery HTML work for both HTML and XML documents?

1 Answers  


What is jquery connect and how to use it?

1 Answers  


How is body onload() function is different from document.ready() function used in jquery?

1 Answers  


Explain the difference between jquery.size() and jquery.length?

1 Answers  


Define the use jquery.data method?

1 Answers  


What is the difference between javascript and jquery?

1 Answers  


How do you stop the currently-running animation?

1 Answers  


Categories