javaScript中循环的使用

  • for 循环遍历数组
var array = [1,2,3,4,5,6,7];  
for (var i = 0; i < array.length; i) {  
    console.log(i,array[i]);  
}  
  • for in 循环遍历数组
for(var index in array) {  
    console.log(index,array[index]);  
};  
  • forEach 循环遍历数组(注意forEach 写法,不能写成foreach)
arr.forEach(function(e){
    console.log(e);
})
发布了33 篇原创文章 · 获赞 3 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/weixin_37189727/article/details/86719147