I have a loop on this form in a code base I'm working on.
for(const foo of data) {
foo.bar = getValue();
}
I want to change this, so that I remove the element foo if a condition based on foo.bar is satisfied. Is this possible within the for-of loop? Or do I need to use another approach? This is my attempt, but I don't feel secure about it. It really looks like one of those things that works until it does not.
for(const x of data) {
foo.bar = getValue();
if(foo.bar > 5)
data.splice(data.indexOf(foo), 1);
}
I know that I could filter the array after creating it. Would that make more sense?
for(let i = data.length-1...).data2 = data.filter( x => getValue(x) > 5)or somethingforloop in which you want to remove elements (problem Y), but you don't know how to do that either, so you ask help about what you believe will solve your original problem (Y), instead of the original problem itself (X).