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)
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved