JavaScript: arrays

An array stores an ordered collection of values. JavaScript uses zero-based indexes, so the first item is at index 0.

What you will learn

Minimal example

const colors = ['red', 'green', 'blue'];
console.log(colors[0]); // "red"
colors[1] = 'lime';
console.log(colors.length); // 3

Use square brackets to read or update an item. The length property tells you how many positions the array currently contains.

Common mistakes