The Array object is used to store multiple values in a single variable.
The following code creates an Array object called myCars:
There are two ways of adding values to an array (you can add as many values as you need to define as many variables you require).
var myCars=new Array();
myCars[0]="Saab";
myCars[1]="Volvo";
myCars[2]="BMW";
Now your array contains:
You can refer to a particular element in an array by referring to the name of the array and the index number. The index number starts at 0.
The following code line:
document.write(myCars[0]);
will result in the following output:
To modify a value in an existing array, just add a new value to the array with a specified index number:
myCars[0]="Opel";
Now, the following code line:
document.write(myCars[0]);