一维数组的遍历
<script>
//循环遍历数组
var
animals = [
"cat"
,
'dog'
,
'human'
,
'whale'
,
'seal'
];
var
animalString =
""
;
for
(
var
i = 0;i<animals.length;i++){
animalString += animals[i] +
" "
;
}
alert(animalString);
//输出数组里的每个项
</script>
遍历二维数组
<script>
var
arr=[[0,0,0,0,0,0],[0,0,1,0,0,0],[0,2,0,3,0,0],[0,0,0,0,0,0]];
for
(
var
i=0;i<arr.length;i++){
//遍历每一个具体的值
for
(
var
j=0;j<arr[i].length;j++){
document.writeln(arr[i][j]+
" "
);
}
document.writeln(
"<br/>"
);
}
</script>