Each item stored in an array is called an array element, and each has a unique number (index) by which we can refer to it.
Like a variable, each array element can store any legal datum. An entire array, then, is akin to a collection of sequentially named variables, but instead of each item having a different name, it has an element number (the first element is number 0, not number 1).
Figure 11-1 shows, conceptually, the structure of an array that contains three elements. Element stores the value "Erica", element 1 stores the value "Slavik", and element 2 stores the value "Gary".
To manipulate the values in an array's elements, we ask for them by number. In our chest of drawers analogy we might ask ActionScript to store something in the first drawer or retrieve whatever is in the second drawer for us.
An element's position in the array is known as its index. Just as we can access the seventh character in a string, we can access the seventh element of an array via its index (in this case, the index is 6). We use an element's index to set or retrieve the element's value or to work with the element in various other ways. Some of the array-handling functions, for example, use element indexes to specify ranges of elements for processing.
We can also insert and delete elements from the beginning, end, or even middle of an array. An array can have gaps (that is, some elements may be absent). We may have elements at positions and 4, but nothing in positions 1, 2, and 3. Arrays with gaps are called sparse arrays.
Every array contains a specific number of elements at any given point during its life span. The number of potential elements an array can hold is called the array's length, which we'll discuss later.
Copyright © 2002 O'Reilly & Associates. All rights reserved.