Free php web host - 995Chapter 37 .The Array Object Multidimensional Arrays An
Friday, July 27th, 2007995Chapter 37 .The Array Object Multidimensional Arrays An alternate to parallel arrays is the simulation of a multidimensional array. While it s true that JavaScript arrays are one-dimensional, you can create a one- dimensional array of other arrays or objects. A logical approach is to make an array of custom objects, because the objects easily allow for naming of object properties, making references to multidimensional array data more readable (custom objects are discussed at length in Chapter 41). Using the same data from the examples of parallel arrays, the following statements define an object constructor for each data record. A new object is then assigned to each of four entries in the main array. // custom object constructor function officeRecord(city, manager, quota) { this.city = city this.manager = manager this.quota = quota } // create new main array var regionalOffices = new Array() // stuff main array entries with objects regionalOffices[0] = new officeRecord( New York , Shirley Smith , 300000) regionalOffices[1] = new officeRecord( Chicago , Todd Gaston , 250000) regionalOffices[2] = new officeRecord( Houston , Leslie Jones , 350000) regionalOffices[3] = new officeRecord( Portland , Harold Zoot , 225000) The object constructor function (officeRecord()) assigns incoming parameter values to properties of the object. Therefore, to access one of the data points in the array, you use both array notations to get to the desired entry in the array and the name of the property for that entry s object: var eastOfficeManager = regionalOffices[0].manager You can also assign string index values for this kind of array, as in regionalOffices[ east ] = new officeRecord( New York , Shirley Smith , 300000) and access the data via the same index: var eastOfficeManager = regionalOffices[ east ].manager But if you re more comfortable with the traditional multidimensional array (from your experience in other programming languages), you can also implement the above as an array of arrays with less code: // create new main array var regionalOffices = new Array() // stuff main array entries with arrays regionalOffices[0] = new Array( New York , Shirley Smith , 300000) regionalOffices[1] = new Array( Chicago , Todd Gaston , 250000) regionalOffices[2] = new Array( Houston , Leslie Jones , 350000) regionalOffices[3] = new Array( Portland , Harold Zoot , 225000)
We recommend high quality webhost to host and run your jsp application: christian web host services.