This grep() method in jQuery is used to finds the elements of an array that satisfies a filter function.
jQuery.grep(array, function(element, index) [, invert])
Parameters: This method accepts two parameters as mentioned above and described below:
- array: This parameter holds the array like object for searching.
- function(element, index): It is the filter function which takes two arguments, element which holds the element of the array and index which holds the index of that particular element.
- invert: It is false or not passed, then the function returns an array having all elements for which “callback” returns true. If this is passed true, then the function returns an array having all elements for which “callback” returns false.
Return Value: It return the elements which satisfies the filter function.
Example 1: In this example, the grep() method is applies on the array of numbers to filter some numbers based on the condition. It doesn’t affect the original array.
- jQuery | jQuery.fx.interval Property with example
- jQuery | jQuery.fx.off Property
- jQuery | jQuery.support Property
- jQuery | jquery Property
- jQuery UI | position() Method
- JQuery | parseHTML() method
- jQuery | css() Method
- jQuery | add() method with Example
- jQuery | not() method with Examples
- jQuery | ajaxStart() Method
- JQuery UI | Progressbar method
- jQuery | get() Method
- jQuery | fadeIn() Method
- jQuery | delegate() Method
- jQuery | outerHeight() Method
- jQuery | event.isDefaultPrevented() Method
- jQuery | outerWidth() Method
- jQuery | before() Method
- jQuery | off() Method
- jQuery | html() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.