JavaScript Array shift() method

Posted on Feb 08, 2021

Learn about JavaScript Array shift() method

The JavaScript Array shift() method allows you to remove the first element (at index zero) of your array, while also returning that element to you. The shift() method does not have any parameters.

Here’s an example of shift() in action:

let programmingLangs = ["JavaScript", "Ruby", "Python"];
let shiftedLang = programmingLangs.shift();

console.log(programmingLangs); // ["Ruby", "Python"]
console.log(shiftedLang); // "JavaScript"

Because the first element is a string, the value returned by shift() is also a string. If your array contains another array or an object, that will be returned as well:

let fruitCart = [
    name: "Apple",
    quantity: 3,
    name: "Orange",
    quantity: 1,
    name: "Banana",
    quantity: 3,

let shiftedFruit = fruitCart.shift();
console.log(shiftedFruit); // { name: "Apple", quantity: 3 }

You can use the shift() method for any array type data you have.

See also: JavaScript methods to remove element from Array

Level up your programming skills

I'm sending out an occasional email with the latest programming tutorials. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.