//遍历数组
var a = ["aaa","bbb","ccc"];
$.each(a,function(i){
console.log(i);//i是数组中元素个数
console.log(a[i]);//数组中的元素
})
//输出结果:
/*
aaa
1
bbb
2
ccc
*/
//遍历json数组
var b = [{name:"jiaojiao",age:"19"},{name:"zhangsan",age:"20"},{name:"lisi",age:"50"}]
$.each(b,function(key,value){
console.log(key);//key 是条数
console.log(value);//value是每一条中的数据
console.log(value.name);//取每一条数据中的字段
//注 value.name == b[i].name
})
//输出结果
/*
0
{name: "jiaojiao", age: "19"}
zhangjiaojiao
1
{name: "zhangsan", age: "20"}
zhangsan
2
{name: "lisi", age: "50"}
lisi
*/