shift() are two methods that remove elements from an array. Take a look at how the method functions and the syntax below.
- Removes the element at the tail
- Returns the removed element
- Removes the element at the head
- Returns the remove element
shift() methods are methods that don't need to be called with a specific parameter. The
pop() method removes the last element while the
shift() method removes the first element of the array. Calling the
pop() method removed the last element 5, which is why version 1 of the array is [1,2,3,4]. Calling the
shift() method then removed the first element of the array, which is why version 2 of the array is [2,3,4]. These two methods are not the same, and are to be used when appropriate.