Answers for "javascript break foreach"

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

foreach break js

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 "Javascript"

Browse Popular Code Answers by Language