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]);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.