Because objects are collections of properties with each property having its own name and value, arrays are actually JavaScript objects. Each property in an array is an element, and each element can be assigned a value. One way to think of an array is as a collection of numbered variables.

An array in JavaScript has the following general formats for assigning values to elements:

sampleArr[1]="ice cream"; 
sampleArr[2]=55 * (7 + alpha); 
sampleArr[3]= shootTheMoon(73); 
sampleArr[4]= otherArr[7]; 


						sampleArr=new Array(1,"ice cream", (55 * (7+ alpha)), shootTheMoon(73), 

or, in JavaScript 1.2 or later:

						sampleArr=[1,"ice cream", (55 * (7+ alpha)), shootTheMoon(73), otherArr[17]]; 

All three arrays are identical, ...

Get JavaScript Design now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.