Previous Example-|-Next Chapter's Examples-|-Return to Chapter Listing

Example 9.5:
Exceeding the Array Length

Click on the buttons to see what is held in the specified positions in the arrays:


This is the script we used in the HEAD: <SCRIPT LANGUAGE="JAVASCRIPT"> <!-- function makeArray(n) { this.length = n for (var i=1; i <= n; i++){ this[i] = null; } return this } var acode = new makeArray(3) var area = new makeArray(3) area[1] = "Alabama "; acode[1] = 205 area[2] = "Alabama "; acode[2] = 334 area[3] = "Alaska "; acode[3] = 907 area[4] = "Alberta "; acode[4] = 403 area[5] = "Antigua "; acode[5] = 268 area[6] = "Arizona "; acode[6] = 520 area[7] = "Arizona "; acode[7] = 602 area[8] = "Arkansas "; acode[8] = 501 area[9] = "Bahamas "; acode[9] = 242 area[10] = "Barbados "; acode[10] = 246 area[11] = "Bermuda "; acode[11] = 441 area[12] = "British Columbia "; acode[12] = 250 area[13] = "British Columbia "; acode[13] = 604 //--> </SCRIPT> And this form: <FORM> <INPUT TYPE="BUTTON" VALUE="What's in area Position 11?" onclick="alert(area[12])"><P> <INPUT TYPE="BUTTON" VALUE="What's in acode Position 11?" onclick="alert(acode[12])"><P> <INPUT TYPE="BUTTON" VALUE="What's in area Position 110?" onclick="alert(area[110])"><P> <INPUT TYPE="BUTTON" VALUE="What's in area Position 500?" onclick="alert(area[500])"><P> <INPUT TYPE="BUTTON" VALUE="What's in area Position 0 (area.length)?" onclick="alert(area.length)"><P> </FORM>
Previous Example-|-Next Chapter's Examples-|-Return to Chapter Listing