$.each in Jquery gets the usage of various return types of data
- 2020-06-03 05:52:21
- OfStack
var arr = [ "one", "two", "three", "four"];
$.each(arr, function(){
alert(this);
});
The above each output is: 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 2-dimensional array, and item is equivalent to taking every 1-dimensional array,
item[0] takes the first value in every 1-dimensional array
So the each output 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); // key
alert(val); // value
});
The output result is: 1, 2, 3, 4
This is the end of this article, I hope you enjoy it.