jquery traversal array with the $.each, the following webmaster gives you a few specific examples:
Example 1. Traverse a normal one-dimensional array:
12345678 |
<script>
//声明数据有下面两种方式
//var aijquery=new Array("a","b","c","d");
var
aijquery=[
"a"
,
"b"
,
"c"
,
"d"
];
$.each(aijquery,
function
(i,v){
document.write(i+
"."
+v+
"\n"
);
//输出结果为:0.a 1.b 2.c 3.d
});
</script>
|
Example 2: Traversing a two-dimensional array in jquery:
123456789 |
var
aijquery=[[
"a.1"
,
"a.2"
],[
"b.1"
,
"b.2"
],[
"c.1"
,
"c.2"
]];
$.each(aijquery,
function
(i,v){
document.write(i+
":"
+v+
"<br>"
);
//这里,把二维数组里的每一个子数组当成上面一维数组里的每一个单独项就好理解了
//因为这个二维数据的每个项其实都是一个一维数组,所以我们可以继续用$.each来循环遍历:
$.each(v,
function
(i,v){
document.write(i+
"."
+v+
"\n"
);
});
});
|
Click here for a detailed online demo: An online example of a jquery traversal array
Methods and examples of traversing ordinary arrays and multidimensional arrays in jquery