To add a new element to an existing array at a specific index: assign a value to that element.
package{
import flash.display.Sprite;
public class Main extends Sprite{
public function Main(){
var fruits:Array = ["apples", "oranges", "pears"];
fruits[3] = "tangerines";
fruits[39] = "grapes";
trace(fruits); // Displays: undefined
trace(fruits[12]); // Displays: undefined
}
}
}
apples,oranges,pears,tangerines,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,grapes
undefined
Related examples in the same category