Home >Web Front-end >JS Tutorial >How to use $.each in Jquery to obtain various return type data_jquery
var arr = [ "one", "two", "three", "four"]; $.each(arr, function(){ alert(this); });
The output results of each of the above are: one, two, three, four
var arr = [ "aaa", "bbb", "ccc" ]; $.each(arr, function(i,a){ alert(i); // i 是循环的序数 alert(a); // a 是值 }); 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 each one-dimensional array,
item[0] is relative to taking the first value in each one-dimensional array
So the output of each above is: 1 4 7
var obj = { one:1, two:2, three:3, four:4}; $.each(obj, function(key, val) { alert(obj[key]); alert(key); //键 alert(val); //值 });
The output result is: 1 2 3 4
The above is the entire content of this article, I hope you all like it.