Chapter VIII · Arrays

Array Indexes

Array indexes represent the numerical position of items in an array, starting at zero.

01 How It Works

Think of sequential apartment door numbers lining a hallway corridor.

Items are addressed via bracket notation containing their exact zero-based integer index.

example.js
const colors = ["red", "green", "blue"];
console.log(colors[0]); // "red"
console.log(colors[2]); // "blue"
  1. 1. Target an array reference variable.

  2. 2. Provide target integer index inside brackets [i].

  3. 3. Retrieve or reassign the item.

02 Practical Example

Here is how you might see this concept applied in real-world code:

practical.js
const items = ["a", "b", "c"];
items[1] = "z"; // Reassign index 1

Key Takeaway

JavaScript arrays are zero-indexed, meaning the first item sits at index 0.

Related Concepts