退出forEach
try { var arr = [1, 2, 3, 4]; arr.forEach(function (item, index) { //跳出条件 if (item === 3) { throw new Error("LoopTerminates"); } //do something console.log(item); });} catch (e) { if (e.message !== "LoopTerminates") throw e;};
参考链接:缩小for的应用