$.each in jquery gets the usage of various return type data

Source: Internet
Author: User
Tags arrays

The each () method makes the DOM loop structure simple and error-prone. The each () function encapsulates a very powerful traversal function and is also handy for traversing one-dimensional arrays, multidimensional arrays, DOM, JSON, and so on, and using $each during JavaScript development can greatly reduce our workload.

1 2 3 4 var arr = ["One", "two", "three", "four"];  $.each (arr, function () {alert (this); });

The results of each output above are: One,two,three,four

1 2 3 4 5 6 7 8 9 var arr = ["AAA", "BBB", "CCC"];  $.each (arr, function (i,a) {alert (i);//I is circular ordinal alert (a);//A Is value});  var arr1 = [[1, 4, 3], [4, 6, 6], [7, 9]] $.each (arr1, function (I, item) {alert (item[0)); });

In fact arr1 is a two-dimensional array, the item is equivalent to taking every one-dimensional array,

Item[0] Relative to the first value in each one-dimensional array

So the above each output is: 1 4 7

1 2 3 4 5 6 var obj = {one:1, two:2, Three:3, four:4}; $.each (obj, function (key, Val) {alert (Obj[key]); alert (key);//Key alert (val);//value});

The output is: 1 2 3 4

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.