O'Reilly logo

Essential ActionScript 3.0 by Colin Moock

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Anatomy of an Array

Each item in an array is called an array element, and each element has a unique numeric position (index) by which we can refer to it.

Array Elements

Like a variable, each array element can be assigned any value. An entire array, then, is akin to a collection of sequentially named variables, but instead of each item having a different name, each item has an element number (the first element is number 0, not number 1). To manipulate the values in an array's elements, we ask for them by number.

Array Element Indexing

An element's position in the array is known as its index. We use an element's index to set or retrieve the element's value or to work with the element in various ways. Some of the array-handling methods, 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 can be empty). We can have elements at positions 0 and 4, without requiring anything in positions 1, 2, and 3. Arrays with gaps are called sparse arrays.

Array Size

At any point during its life span, a given array has a specific number of elements (both empty and occupied). The number of elements in an array is called the array's length, which we'll discuss later in this chapter.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required