Arrays and Loops: Final Words

I realize that the information that I've given you concerning arrays and loops is pretty abstract. Really writing your own arrays and loops for real world purposes is beyond the scope of this class. However, a good portion of elements on an HTML page are declared, initialized, and stored in JavaScript using arrays. You will be using loops frequently to access pre-existing arrays, and either pulling information out of an array, or affecting the contents of an array in some manner.

Every image on a web page, for instance, is stored, in order of their appearance in the HTML code, in the images[] array; the first IMG on the HTML page is stored in images[0], the second IMG on the HTML page is stored in images[1], etc. You can affect the images on an HTML page by accessing their image object instances via this array (there are also other, more direct means, as well). Countless other HTML elements are stored in a similar manner.

In the next section, we are going to look at a FORM, and access elements in the form using dot syntax and array syntax; we will do this in order to extract the user's selected choice from a form pulldown menu.

Main Menu