Professional web hosting - 78Part IIJavaScript Tutorialcollections is small enough not to

78Part IIJavaScript Tutorialcollections is small enough not to severely impact page loading even for dial-up users at28.8 Kbps. In Chapter 30, you also see some syntax shortcuts for creating arrays that reducesource code character counts. Accessing array dataThe array index is the key to accessing an array element. The name of the array and an indexin square brackets evaluates to the content of that array location. For example, after theUSStatesarray is built, a script can display an alert with Alaska s name in it with the follow- ing statement: alert( The largest state is + USStates[1] + . ); Just as you can retrieve data from an indexed array element, so can you change the elementby reassigning a new value to any indexed element in the array. Parallel arraysNow I show you why the numeric index methodology works well in JavaScript. To help withthe demonstration, I generate another array that is parallel with the USStatesarray. Thisnew array is also 51 elements long, and it contains the year in which the state in the corre- sponding row of USStatesentered the Union. That array construction looks like thefollowing: var stateEntered = new Array(51); stateEntered [0] = 1819; stateEntered [1] = 1959; stateEntered [2] = 1912; stateEntered [3] = 1836; … stateEntered [50] = 1890; In the browser s memory, then, are two data tables that you can visualize as looking like themodel in Figure 7-1. I can build more arrays that are parallel to these for items such as thepostal abbreviation and capital city. The important point is that the zeroth element in each ofthese tables applies to Alabama, the first state in the USStatesarray. Figure 7-1:Visualization of two related parallel data tables. “Alabama” “Alaska” “Arizona” “Arkansas” “Wyoming” 18191959191218361890[0] [1] [2] [3] [50] stateEnteredUSStates…. …. ….
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision servlet hosting services