How to use $. each in Jquery to obtain various types of returned data _ jquery

Source: Internet
Author: User
The each () method simplifies the DOM loop structure and is not prone to errors. The each () function encapsulates powerful traversal functions and is easy to use. It can traverse one-dimensional arrays, multi-dimensional arrays, DOM, JSON, and so on, using $ each in javaScript development can greatly reduce our workload.
Var arr = ["one", "two", "three", "four"]; $. each (arr, function () {alert (this );});

The above each output results are: one, two, three, four

Var arr = ["aaa", "bbb", "ccc"]; $. each (arr, function (I, a) {alert (I); // I is the ordinal number of the loop alert (a); // a is the value }); 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.
Therefore, 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]); alert (key); // key alert (val); // value });

Output result: 1 2 3 4

The above is all the content of this article. I hope you will like it.

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.