How to Use jquery to traverse arrays and Filter Arrays _ jquery-js tutorial

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


Related Article

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.