Sikau

JavaScript · Day 31 · about 25 min

Adding and removing

push, pop and friends.

Lists that grow and shrink

A queue at the bank changes all day: people join at the back and leave from the front. Arrays have methods for exactly this.

At the end: push and pop

const queue = ["Asha", "Bikash"];
queue.push("Chandra");
console.log(queue);

const last = queue.pop();
console.log(last);
console.log(queue);

The rest of this lesson

  • At the front: unshift and shiftexplain
  • Methods that change the arrayexplain
  • Predict the outputpredict
  • Queue at the bankpredict
  • Your turnwrite code
  • Challengechallenge
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 68 lessons of JavaScript