[JavaScript]
[Previous page] [Section contents page] [Next page]
The Array Object

An array is an ordered set of data, similar to a table. In JavaScript, arrays are one-dimensional, meaning that you can create a table of data with one column (and as many rows as you like). Arrays are powerful programming tools because they allow you to create a structured set of data, any item of which can be accessed with short statement.

To create an array you need to create a new array, and then populate it with data, as in the following example:

	Example:

<script language="JavaScript"> <!-- monthArray = new Array(12) // note that array numbering starts at zero; // this method does not work for Netscape 2.0x // on account of bugs in the JavaScript implemenation monthArray[0] = 'January' monthArray[1] = 'February' monthArray[2] = 'March' monthArray[3] = 'April' monthArray[4] = 'May' monthArray[5] = 'June' monthArray[6] = 'July' monthArray[7] = 'August' monthArray[8] = 'September' monthArray[9] = 'October' monthArray[10] = 'November' monthArray[11] = 'December' /* The following code writes the values of the array to the document */ var x = 0 while ( x <=11 ) { document.write('monthArray[' + x + '] = ' + monthArray[x] + '<br>') x++ } // --> </script>

Below you will see the output from this script:

[Previous page] [Section contents page] [Next page]