退出forEachoop
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的使用.net