Arrays

Declaring and Instantiating an Array
An array is a special type of variable. It doesn't just store one value; it stores a list of values. You should consider using an array whenever you are working with a list or a set of values that are related to each other. For example, an array can be suited to storing the individual items on a shopping list because it is a list of related items.

Use the following syntax to create an Array:
tutorial

Accessing and Changing Array Items
Each item in an array is automatically given a number called an index. This can be used to access specific items in the array. Confusingly, index values start at 0 (not 1).

To retrieve the third item on the list, the array name is specified along with the index number in square brackets:
tutorial

Here you can see a variable called itemThree is declared. Its value is set to be the third color from the colors array.

You can change the value of an item an array by selecting it and assigning it a new value using the equals sign and the new value for that item:
tutorial

The third item on the list is changed from 'custom' to 'beige'.

Array Length
Each array has a property called length, which holds the number of items in the array. The name of the array is followed by a period symbol which is then followed by the 1ength keyword.
tutorial

You can see that a variable called numColors is declared. Its value is set to be the number of the items in the array.

NEXT LESSON