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

Example 9.9:
Assigning String Values to Arrays

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

This time we created an array and assigned string values to the elements. These become properties of the elements, and can be referenced like a property (house.bedrooms, for instance).


This is the script we used in the HEAD: <SCRIPT LANGUAGE="JAVASCRIPT"> <!-- var house = new Array(0) house["color"] = "white" house["style"] = "ranch" house["bedrooms"] = 3 house["baths"] = 2 //--> </SCRIPT> And here's the script in the BODY: <SCRIPT LANGUAGE="JAVASCRIPT"> <!-- document.write("<BR>house Array length: " + house.length) document.write("<BR>house color: " + house.color) document.write("<BR>house style: " + house.style) document.write("<BR>number of bedrooms: " + house.bedrooms) document.write("<BR>number of baths: " + house.baths) //--> </SCRIPT>
Previous Example-|-Next Example-|-Return to Chapter Listing