Module 11 Arrays

The following are examples of Arrays.



Understanding Arrays

An array is a way of storing data of similar types for easy access later in a script. In JavaScript an array is basically a user-defined object that is typically accessed in a different way than other opbjects. In a regular array, access to an element is usually through the use of an index number. An associative array allows access using a string in place of a number.

Defining an array is similar to creating an instance of an object. In fact, one method of defining an array looks and acts just like the method of creating an instance of an object.

Below is the start of simple arrays. They list the Top 20 in the NASCAR Cup and Busch Series. From there we will access the arrays to show different ways of calling the data stored.

Simple Arrays



NASCAR Top 20

Cup Series Busch Series

Now say I just wanted to show the Cup Drivers that also drive fulltime in the Busch Series. Using a simple document.write, I can tell it to only show the drivers I want it to show by specifying the number that they are on the list. Keep in mind, the list starts at 0 (zero), not 1 (one) for numbering of items.

NASCAR Top 20

Cup Series Double Dippers

To be fair, lets show the Busch Drives that double dip too!

NASCAR Top 20

Busch Series Double Dippers

There are, of course, many things you can do with arrays. This is just a small, small portion. But like other things in JavaScript, it's not difficult once you get the hang of it.

Return to the top of the page.