js break for each loop code example
Example 1: javascript foreach break
//Use some instead
[1, 2, 3].some(function(el) {
console.log(el);
return el === 2;
});
Example 2: continue foreach javascript
elementsCollection.forEach(function(element){
if (!element.shouldBeProcessed)
return; // stop processing this iteration
// This part will be avoided if not neccessary
doSomeLengthyOperation();
});