Reputation: 5952
Is it impossible to use 'continue' with forEach ? Following gives errors.
var numbers = [4, 9, 16, 25];
function myFunction() {
numbers.forEach(function(val){
if(index==2){
continue;
}
alert('val: '+val);
});
}
Is there any other work around to use continue?
Upvotes: 2
Views: 5784
Reputation: 8545
var numbers = [4, 9, 16, 25];
function myFunction() {
numbers.forEach(function(val, index){
if(index!=2)
alert('val: '+val);
});
Upvotes: -1
Reputation: 943215
Is it impossible to use 'continue' with forEach ?
Yes.
Is there any other work around to use continue?
Use return
to exit a function immediately.
Upvotes: 11