Home  >  Article  >  Web Front-end  >  Jquery中的$.each获取各种返回类型数据的使用方法_jquery

Jquery中的$.each获取各种返回类型数据的使用方法_jquery

WBOY
WBOYOriginal
2016-05-16 16:01:361137browse
var arr = [ "one", "two", "three", "four"]; 
$.each(arr, function(){ 
alert(this); 
}); 

上面这个each输出的结果分别为: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]); 
}); 

其实arr1为一个二维数组,item相当于取每一个一维数组,
item[0]相对于取每一个一维数组里的第一个值
所以上面这个each输出分别为: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); //值
}); 

输出结果为:1 2 3 4

以上所述就是本文的全部内容了,希望大家能够喜欢。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn