Previous Example-|-Next Example-|-Return to Chapter Listing

Example 9.6:
Using the Array Object

[This example works with Netscape Navigator 3 and Internet Explorer 3.]

We created an array named info using the new Array object, then use the showArray() function to write the length and contents of the array to this page.


This is the script we used in the HEAD: <SCRIPT LANGUAGE="JAVASCRIPT"> <!-- var info = new Array(3) info[0] = 123 info[1] = 456 info[2] = 789 function showArray(a) { var l = a.length var i document.write("<BR>Array length is " + l + ".<BR>") for (i = 0; i < l; i++) { document.write("Item " + i + " is " + a[i] + ".<BR>") } } //--> </SCRIPT> And here's the script in the BODY: <SCRIPT LANGUAGE="JAVASCRIPT"> <!-- showArray(info) //--> </SCRIPT>
Previous Example-|-Next Example-|-Return to Chapter Listing