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?