forEach抛出异常跳出循环
const list = [1, 2, 3, 4, 5, "a", "b", "c", "d", "e"];
try {
list.forEach((itm) =...> {
if (itm === "c") {
throw new Error("exit");
}
console.log(itm...}
splice变相跳出循环
const list = [1, 2, 3, 4, 5, "a", "b", "c", "d", "e"];
Object.assign(list).forEach((itm..., idx, arr) => {
if (itm == "c") {
arr.splice(idx, arr.length - idx);
}
console.log...(itm);
});