$. Each in jQuery, jquery. each

Source: Internet
Author: User

$. Each in jQuery, jquery. each

With this function, you can traverse and process the attribute values of objects and arrays.

Instructions for use

The effect of the each function based on the parameter type is different:

1. Traverse objects (with additional parameters)

$. Each (Object, function (p1, p2) {this; // here this points to the current property value of the Object in each traversal p1; p2; // access additional parameter }, ['parameter 1', 'parameter 2']);

2. traverse the Array (with attachment parameters)

$. Each (Array, function (p1, p2) {this; // here this points to the current element p1; p2 in each traversal; // access additional parameter }, ['parameter 1', 'parameter 2']);

3. Traverse objects (no additional parameters)

$. Each (Object, function (name, value) {this; // this points to the value name of the current attribute; // name indicates the name value of the current attribute of the Object; // value indicates the value of the current property of the Object });

4. traverse the Array (no additional parameters)

$. Each (Array, function (I, value) {this; // this points to the current element I; // I indicates the current subscript value of the Array; // value indicates the current element of the Array });

The following describes some common usage of jQuery's each method.

Js Code

Var arr = ["one", "two", "three", "four"]; $. each (arr, function () {alert (this) ;}); // The above each Outputs one, two, three, four var arr1 = [[1, 4, 3], [4, 6, 6], [7, 20, 9] $. each (arr1, function (I, item) {alert (item [0]) ;}); // In fact, arr1 is a two-dimensional array, and item is equivalent to taking every one-dimensional array, // item [0] is relative to the first value in each one-dimensional array. // The above each output is: 1 4 7 var obj = {one: 1, two: 2, three: 3, four: 4}; $. each (obj, function (key, val) {alert (obj [key]) ;}); // This each is more powerful, can loop every attribute // The output result is: 1 2 3 4

This article is here to briefly describe jQuery. $. How to Use each. I hope my friends will like it.

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.