1.var signArray=[];//相当于 var signArray = new Array();
ar arr = ["one","two","three","four","five"];
var obj = { one: 1, two: 2, three: 3, four: 4, five: 5 };
遍历数组
var text ="Array ";
i:表示索引,从0开始。
jQuery.each(arr,function(i, val) {
text = text +" #Index:" + i +":" + val;
});
console.log(text);
//Array #Index:0:one #Index:1:two #Index:2:three #Index:3:four #Index:4:five
遍历对象
text ="Object ";
i:表示键;val:表示值;
jQuery.each(obj,function(i, val) {
text = text +"Key:" + i +", Value:" + val;
});
console.log(text);
//Object Key:one, Value:1Key:two, Value:2Key:three, Value:3Key:four, Value:4Key:five, Value:5
网友评论