JavaScript Arrays

Example of creating a array.

var myA = new Array();  // define a array
myA[0] = "one";         // assign values to elements
myA[1] = "two";
myA[3] = "four"; // out of bound reference automatically extend the array
document.write("myA is:" + myA);           // print array
document.write("length is:" + myA.length); // show length
document.write("myA[3] is:" + myA[3]);     // access a element

Alternative way to create a array.

var myA = new Array("pa", "re", "ci");
document.write(myA);

Reference: http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Literals#Array_Literals


See also:


Page created: 2005-08.
© 2005 by Xah Lee.
Xah Signet