I want to able to skip an iteration in this for in break is just stopping it..
for (const property in data) {
if (property === 'user' && !context.user) {
break;
}
localStorage.setItem(property, data[property]);
}
How to skip an iteration if certain condition is met in a for loop
You are using the break, it will exit the loop. Using continue to skip current looping, and jump to next round.
for (const property in data) {
if (property === 'user' && !context.user) {
continue;
}
localStorage.setItem(property, data[property]);
}
You should use continue instead of break
OR
for (const property in data) {
if (property !== "user" || context.user) {
localStorage.setItem(property, data[property]);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With