×

typescript · level 1 · unit 6 · lesson 2

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

Every item in an array has an , starting at 0.

Each item has a position number called an index. Counting starts at 0, so queue[0] is the first item and queue[1] the second. The last one is queue[queue.length - 1].

Put a new value at an index to replace that item, like queue[1] = "Dev";. To add an item to the end, it on: queue.push("Eli");.

Ask for an index past the end and you get , which means no value has been put there. The checker cannot spot this one, so count carefully.

let queue: string[] = ["Ava", "Ben", "Cleo"];
console.log(queue[0], queue[queue.length - 1]);
queue[1] = "Dev";
queue.push("Eli");
console.log(queue);

The index is always one less than the place in the queue, so the third person is at index 2.