遍历数组元素

Js入门与实战 admin 881浏览
<script>
//将数组里面的元素挨个打印
var a1=['Q','s','c',1,4,9,'奥特曼','篮球'];
console.log(a1[0]);
console.log(a1[1]);
console.log(a1[2]);
</script>	
<script>
//使用for循环打印
for(var i=0;i<a1.length;i++){
console.log(a1[i]);
}
</script>	
//使用while打印
<script>
var i=0;
while(i<a1.length){
console.log(a1[i]);
i++
}
</script>

转载请注明:大灰牛博客 » 遍历数组元素