var myArr = new Array();
var myArr = new Array(5);
Also note that if you have defined the array size then you can add values for the array indexes 0 to 4.
Example for array having no size defined
var myArr = new Array(); myArr = "John"; myArr = "Tim"; myArr = "Smith"; myArr = "Jack";
Example for array having size limit defined
var myArr = new Array(3); myArr = "John"; myArr = "Tim"; myArr = "Smith";
var myArr = new Array( "John", "Smith", "Tim");
You can directly call the array values by passing the specific index of the array: alert(myArr);
Above code will display the value stored at the first i.e. 0th index of array.
If you have passed the two different values for the same index of an Array then calling that particular index will return the last value stored in it.
var myArr = new Array(); myArr = "John"; myArr = "Smith"; myArr = "Tim"; alert(myArr);
Above code will display the value "Tim" for 0th index.