Tags: it classification: Jquerygrep () method for array element filtering filtering grep (Array,callback,invert) array: array to be filtered; callback: Processes each element in the array and filters the element, which contains two parameters, The first is the value of the current array element, and one is the subscript for the current array element, which is the element index value. This function should return a Boolean value. In addition, this function can be set to a string that, when set to a string, is considered "Lambda-form" (abbreviated form?). ), where a represents an array element, and I represents the index value of an element. such as "a > 0" means "function (a) {return a > 0;}" Invert: boolean selectable, default value false, value TRUE or FALSE, if "invert" is false or set, the function returns the element in the array that is true by the filter function, and returns false in the return filter function when "invert" is true Set of elements. var arr=$.grep ([0,1,2,3,4,5,6],function (n,i) {return n>2}), the above example returns [3,4,5,6], but we give invert a value of true, such as Var arr=$.grep ([0,1,2,3,4,5,6],function (n,i) {return n>2},ture); So now the return is [0,1,2], which is the element that was filtered out by the callback function.
The use of the $.grep () method in jquery