Array with a Skipped Value

This lesson goes over how to skip a value on an array.

An array doesn’t require all their indices to be defined sequentially.

const arr = [0, 1, 2, 3, 4]; // Unskipped array

When an index is skipped, it is undefined by default. There are two ways to have an array that skips elements.

The first is when the array is defined. Elements defined between brackets can skip a single element by having two commas next to each other. In the following example, line 1 defines a skipped array. It starts with 0, then skips the expected 1, 2.

Get hands-on with 1400+ tech skills courses.