标签:art 退出 function length break row for循环 tin pre
var arr = [1,2,3,4,5,6,7,8]
for(var i=0, len = arr.length ; i< len ; i++){
if(i == 2){
continue;
}
console.log(i);
}
//0,1,3,4,5,6,7
for(var i=0, len = arr.length ; i< len ; i++){
if(i == 2){
break;
}
console.log(i);
}
// 0,1
退出方式同for循环
$.each(arr,function(index,oo){
if(index == 2){
return true;
}
console.log(oo);
})
// 1,2,4,5,6,7,8
$.each(arr,function(index,oo){
if(index == 2){
return false;
}
console.log(oo);
});
// 1,2,3
arr.forEach(function(oo,index){
if(index == 2){
return;
//return false; //效果同上
// return true; //效果同上
}
console.log(oo);
});
// 1,2,4,5,6,7,8
try{
arr.forEach(function(oo,index){
if(index == 2){
throw ‘jumpout‘;
}
console.log(oo);
});
}catch(e){
}
// 1,2
标签:art 退出 function length break row for循环 tin pre
原文地址:https://www.cnblogs.com/justyouadmin/p/13276463.html