var array = [1,2,3,4,5];
try {
// 执行到第3次,结束循环
array.forEach((item, index)=> {
// debugger
if (item == 3) {
throw new Error("跳出循环");
}
console.log(item); //1,2
});
}
catch (e) { // 抛出异常
console.error(e);
};
// 下面的代码不影响继续执行
console.log("继续执行");```