var array = ["first","second","third","fourth"];
// 会遍历数组所有元素,只是执行到第3次师,return false下面的代码不再执行而已
array.forEach(function(item,index){
if (item == "third") {
return false;
}
console.log(item);// first,second,fourth
});
// 跳出条件以后的循环
try {
var arr = ["first","second","third","fourth"];
arr.forEach((item, index) => {
if(item === 'five') {
throw new Error('End 本次')
}
console.log(item)
})
} catch (e) {
// console.log(e.message)
if(e.message !== 'End 本次') throw e // 不用输出e
}
console.log('继续执行')