arr= [1,2,3];
for(var i=0;i<arr.length;i++){
setTimeout(function(){console.log(arr[i])},0);
}
for(var j in arr){
setTimeout(function(){console.log(arr[j])},0);
}
arr.forEach(function(v,k){
setTimeout(function(){console.log(arr[k])},0);
})
for(var value of arr){
setTimeout(function(){console.log(value,0);},0);
}
从上往下执行结果依次如下箭头所示:
网友评论