Jquery provides multiple methods and functions to traverse and Filter Arrays, including grep, each, inArray, and map. json objects must also be traversed, the following describes the specific operation methods.
Grep
The grep () method is used to filter array elements.
Grep (array, callback, invert)
Array: the array to be filtered;
Callback: process each element in the array and filter the elements. This function contains two parameters. The first is the value of the current array element, and the other is the subscript of the current array element, that is, the element index value. This function should return a Boolean value. In addition, this function can be set to a string. When it is set to a string, it will be treated as "lambda-form" (abbreviated form ?), A Indicates the array element, And I indicates the element index value. For example, "a> 0" indicates "function (a) {return a> 0 ;}"
Invert: Boolean option. The default value is false. The value is true or false. If "invert" is false or set, the function returns the elements in the array that are returned by the filter function, if "invert" is true, the system returns the Element Set of false in the filter function.
The Code is as follows: