Skip to content
Advertisement

Skipping an index in foreach loop

I’ve seen options for only hitting certain numbers in a foreach (if i < 25, etc) but I’m wondering how to best skip a string index completely

I have a loop that works perfectly and I don’t want to change what it’s doing, I just want to omit one row that has the index of ’employee’

I’ve tried the below but it doesn’t seem to work as I get a syntax error at my if statement

JavaScript

Advertisement

Answer

Considering you want to leave the loop body in tact, here is one possible non-destructive approach. Not checking anything on every iteration also saves you a little bit of performance loss. See comments for step-by-step explanation.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement