It is standard practice to continue
inside a loop if a certain condition is met/unmet. In a Javascript forEach
loop, this produces a syntax error:
const values = [1, 2, 3, 4, 5];
values.forEach((value) => {
if (value === 3) { continue; }
console.log(value);
})
SyntaxError[ ... ]: Illegal continue statement: no surrounding iteration statement
This happens whether I use function
or an arrow function. How can you continue
inside a forEach
loop?
Obviously, you could do an inverse case (if (value !== 3) { ... }
), but that is not what I'm looking for.