Hey I have a simple loop which iterates a bunch of objects and checks if they match a variable and if they do, I want to remove it from the that list.
But i don’t know how to do it… this is the idea of what I am trying to do :
//my_objects is global (window.my_objects)
for(var i in my_objects){
if(my_objects[i].value == 100){
//remove it
}
}
Is there any option besides creating an array for it ? I could only find delete which only deletes the property which means the object will still be itereated through my loop next time around.
This function is called every X seconds.
Deleting the property from the object like this means that it won’t be in the iteration next time:
Note: this removes the object in question as a property on
my_objects. If there is no other code with a reference to the now removed object, then it will be available for garbage collection and eventually freed.