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

Example 9.7:
Automatically Extending the Array

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

This is much the same as the previous example, but this time we've assigned the words the end to array element 9; as the array is not that long, JavaScript has to extend the array for us.


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"> <!-- info[9] = "the end" showArray(info) //--> </SCRIPT>
Previous Example-|-Next Example-|-Return to Chapter Listing