How to use array shift in JavaScript
Overview
The shift function in JavaScript removes the starting element of an array and returns it. The general syntax of the shift function is as follows:
array.shift()
Parameters
The shift function takes no mandatory inputs as parameters.
Return value
The shift function returns the element that has been removed from the array.
Example
The example below will help you understand the shift function better. First, we create the array and call the shift function on it. We store the returned value in a variable and print to see that it is indeed the first element of the array.
Moreover, printing the array shows that the first element has been removed.
const arr1 = [1,2,3]const first = arr1.shift()console.log(first)console.log(arr1)
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved