The use of the $.grep () method in jquery

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.