第一种:for(...in...)循环输出数组下标

var arr = ["a","b","c","d"];
 
//in:循环输出数组下标
for(let i in arr){
	console.log(i);		//0,1,2,3
}

  

第二种:for(...of...)循环输出数组的值

var arr = ["a","b","c","d"];
 
//of:循环输出数组的值
for(let i of arr){
	console.log(i);		//a,b,c,d
}

  

第三种:for(......)循环输出数组的下标

var arr = ["a","b","c","d"];
 
//of:循环输出数组的值
for(let i=0;i<arr.length;i++){
	console.log(i);		//0,1,2,3
}

  

posted on 2020-04-28 17:49  效率的九尾  阅读(642)  评论(0编辑  收藏  举报