📜  javascript break foreach - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:29.728000             🧑  作者: 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;
}