An array is simply a list. We will declare an array with 3 messages:
var messages: Array=new Array("You can do it!","Keep up the good work!","Way to go!");
We now have an array names messages that has 3 items. The individual items in an array can be referred to using their position in the listing, starting with ZERO. Thus messages[0] is “You can do it!”
One of the reasons that arrays are so useful is that we can use a variable as the index instead of a constant. If n has a value of 2 then messages[n] is “Way to go!”
We could also have declared the array with no initial values:
var messages: Array=new Array();
We could then add values to the array by assigning a value:
messages[0]=”You can do it!”;
We can also add new items to the end of the list by using the push method:
messages.push("Good job!");