1.forEach方法跳出循环----通过抛出异常的方式跳出循环 通过return跳过当次循
var arr=[1,3,5,7,9];
var id = 5;
try{
arr.forEach(function(curItem,i){
if(curItem===1)return;
console.log(curItem);
if(curItem===id){
throw Error();
}
})
}catch(e){
console.log(e)
}
2.for方法跳出循环-----break跳出循环 continue跳出当次循环
var arr=[1,3,5,7,9];
var id = 5;
for(var i=0;i<arr.length;i++){
if(arr[i]===1)continue;
console.log(arr[i])
if(arr[i]===id){
break;
}
}