Answers for "how to break the foreach loop in javascript"

27

javascript break foreach

//break out of for loop
for (i = 0; i < 10; i++) {
    if (i === 3) { break; }
}
Posted by: Guest on July-23-2019
12

javascript foreach break

//Use some instead
[1, 2, 3].some(function(el) {
  console.log(el);
  return el === 2;
});
Posted by: Guest on May-20-2020
3

how to break the foreach loop in javascript

var BreakException = {};

try {
  [1, 2, 3].forEach(function(el) {
    console.log(el);
    if (el === 2) throw BreakException;
  });
} catch (e) {
  if (e !== BreakException) throw e;
}
Posted by: Guest on May-07-2020

Code answers related to "how to break the foreach loop in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language