Skip over an iteration of a for loop in JavaScript?

Answered
yaboy01 asked this question 21 days ago
yaboy01 21 days ago

I have a JavaScript for loop similar to this:

for (var i=0; i < array.length; i++) {
  if (array.name === "billy") {
    // do something
  } else {
    // skip this iteration of the loop
  ]
}

What code do I skip a current iteration of the loop, but keep going as usual?

2 suggested answers
·
1 reply
nick 13 days ago

You're looking for the continue statement:

continue

It tells the loop to jump over one iteration and continue on to the next one.

0 replies
itsbambi 13 days ago

Use continue:

for (var i=0; i < array.length; i++) {
  if (array.name === "billy") {
    // do something
  } else {
    continue
  ]
}
1 reply
yaboy01 13 days ago

Thank you!

Answered