This is not a question of what command to use. I could pop, shift, splice or slice it out of there (hey, that had a nice ring to it…)
My question is how to properly remove items from an array while in the middle of a for loop:
//This will cause errors, because if the condition is met, it will skip the next array in line
for (var i:int = 0; i < arr.length; i++)
{
if (arr*.alpha <= 0)
{
arr.splice(i, 1);
}
}
So, what is the most common workaround? This might work:
//This will cause errors, because if the condition is met, it will skip the next array in line
for (var i:int = 0; i < arr.length; i++)
{
if (arr*.alpha <= 0)
{
arr.splice(i, 1);
i--;
}
}
Silly question, but is this the ideal or most common way to do it? If someone is reading through my code, will they understand what I am doing without me having to clarify with comments each time?