if you assign a value to an element that has not yet been created, actionscript creates that element, and any other elements with indices between. : Array Index « Array « Flash / Flex / ActionScript






if you assign a value to an element that has not yet been created, actionscript creates that element, and any other elements with indices between.

 

package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){


        var aEmployees:Array = new Array(4);
        aEmployees[0] = "A";
        aEmployees[1] = "P";
        aEmployees[2] = "C";
        aEmployees[3] = "H";
        
        aEmployees[9] = "Ruth";
        
        
        trace(aEmployees.toString());  //A,P,C,H,,,,,,Ruth
    }
  }
}

        








Related examples in the same category

1.Referencing Array Elements
2.Read the data from an array using array-access notation to access one element at a time.
3.Adding Values to an Array: Assigning Values Using Array-Access Notation
4.Use variables or complex expressions to specify an element index
5.Sum the array elements
6.Setting an Element's Value
7.Use variable as the array index
8.To add a new element to an existing array at a specific index: assign a value to that element.
9.Adding New Elements with the length Variable