×

javascript · 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.

Picture a queue at an ice cream van. JavaScript numbers each place in the queue, starting at 0, not 1. That number is the index, so queue[0] is the person at the front.

The last index is one less than the length, so queue[queue.length - 1] is the back of the queue. Ask for a place nobody is in and you get , meaning no value.

To swap someone, use = with an index: queue[1] = "Dev"; puts Dev in place 1. To add someone, them: queue.push("Eli"); puts Eli on the end.

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

Use square brackets to read an item and round brackets for a method like .push().