Short circuit Array.forEach like calling break Short circuit Array.forEach like calling break arrays arrays

Short circuit Array.forEach like calling break


There's no built-in ability to break in forEach. To interrupt execution you would have to throw an exception of some sort. eg.

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