📜  foreach 中断 js - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:41.138000             🧑  作者: Mango

代码示例2
var BreakException = {};

try {
  [1, 2, 3].forEach(function(el) {
    console.log(el);
    if (el === 2) throw BreakException;
  });
} catch (e) {
  if (e !== BreakException) throw e;
}