When you remove elements from an array in a for statement, you need to change the value of the index variable accordingly : Splice : Array Flash / Flex / ActionScript examples


Flash / Flex / ActionScript examples » Array » Splice »

 

When you remove elements from an array in a for statement, you need to change the value of the index variable accordingly


 

package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
        var numbers:Array = new Array(410);
        numbers[41;
        trace(numbers);  // Displays: 4,10,undefined,undefined,1
        
        for(var i:int 0; i < numbers.length; i++) {
            if(numbers[i== undefined) {
                numbers.splice(i, 1);
            }
        }
        trace(numbers);  // Displays: 4,10,undefined,1
    }
  }
}
// 4,10,,,1
// 4,10,,1

        



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


Flash / Flex / ActionScript examples

 Navioo Array
» Splice