...

Accessing Array Elements

Now that we can create arrays, we need to access individual items inside them. Each item in an array can be accessed using its index.

Given the following array:

let colors = ["red", "blue", "green"];

We can access the first element "red" using:

colors[0];  // "red" is at index 0, not 1

Notice that array indexes start at 0, not 1. So the first item is at index 0, the second item is at index 1, and so on.

Your Task

Print out each color individually using its index. Print all 4 colors: the first at index 0, the second at index 1, the third at index 2, and the fourth at index 3.

Variables

No variables

Loading...

Output (Console)