JavaScript

Push Pop Shift Unshift
14.01.2022
img


Methods pop/push, shift/unshift

A queue is one of the most common uses of an array. In computer science, this means an ordered collection of elements which supports two operations:

  • push appends an element to the end.
  • shift get an element from the beginning, advancing the queue, so that the 2nd element becomes the 1st.
In practice we need it very often. For example, a queue of messages that need to be shown on-screen.There’s another use case for arrays – the data structure named stack. It supports two operations:
  • push adds an element to the end.
  • pop takes an element from the end.
Looking the picture we can make anchor to memorize: 
  • on the left POP and SHIFT that take from array elements, 
  • on the right PUSH and UNSHIFT that add elements.
Both methods pUSH and UnSHift have three common letters .

back to all posts