遍历数组
程序员文章站
2022-07-15 08:19:12
...
1.for循环遍历
<script>
var arr=['a','b','c','d'];
for(var x=0,len=arr.length;x<len;x++){
console.log(arr[x]);
}
</script>
2.for...in遍历数组
<script>
var arr1=[];
arr1[11]='a';
arr1[22]='b';
arr1[33]='c';
for(var x in arr1){
console.log(arr1[x]);
}
</script>
3.forEach()遍历数组
语法:
Array.forEach(function(){函数体});
<script>
var arr2=[1,2,3,4,5,6];
arr2.forEach(function(x){
console.log(x);
})
</script>
上一篇: rabbitmq 集群的安装
下一篇: 取余和取模的区别