jquery遍历数组
程序员文章站
2022-07-15 08:18:00
...
jquery遍历数组
for遍历:
var arr = new Array(1,2,3,4,5,6);
for(var i=0;i<arr.length;i++){
arr[i] ;
}
for in 遍历:
var x;
var arr = new Array(1,2,3,4,5,6);
for (x in arr )
{
arr [x];
}
each遍历一维数组:
var arr=["1","2","3"];
$.each(arr,function(index,value){
alert(index+"..."+value);
});
each遍历二维数组:
$(function () {
$.each([["1", "2", "3"], ["4", "5", "6"], ["7", "8", "9"]], function (index, item) {
alert(index + ":" + item);
//输出0:1,2,3 ...1:4,5,6...2:7,8,9
//这时的index为数组下标,item相当于取这二维数组中的每一个数组
$.each(item, function (index, itemobj) {
alert(index + ":" + itemobj);
});
});
});
下一篇: java遍历数组并重新拼接数组里的元素