foreach skip iteration javascript code example
Example 1: continue foreach javascript
elementsCollection.forEach(function(element){
if (!element.shouldBeProcessed)
return; // stop processing this iteration
// This part will be avoided if not neccessary
doSomeLengthyOperation();
});
Example 2: foreach in javascript skip first
let arr = [1, 2, 3, 4, 5];
arr.slice(1).forEach(function(value) {
console.log(value);
});