forEach循环,break跳出不起作用,需要使用抛出异常的方式跳出循环
try {
this.diffList.forEach(item => {
if (item.id == '1') {
//跳出循环
//抛出异常,跳出循环
throw new Error("EndIterative");
}
});
} catch (e) {
if (e.message != "EndIterative") {
throw e;
}
}
forEach循环,break跳出不起作用,需要使用抛出异常的方式跳出循环
try {
this.diffList.forEach(item => {
if (item.id == '1') {
//跳出循环
//抛出异常,跳出循环
throw new Error("EndIterative");
}
});
} catch (e) {
if (e.message != "EndIterative") {
throw e;
}
}