The following code creates an Array object called myCars:
var myCars=new Array(); |
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).
1:
var myCars=new Array(); myCars[0]="Saab"; myCars[1]="Volvo"; myCars[2]="BMW"; |
You could also pass an integer argument to control the array's size:
var myCars=new Array(3); myCars[0]="Saab"; myCars[1]="Volvo"; myCars[2]="BMW"; |
2:
var myCars=new Array("Saab","Volvo","BMW"); |
Note: If you specify numbers or true/false values inside the array then the type of variables will be numeric or Boolean instead of string.
0 comments: