Friday, October 17, 2025
HomeLanguagesJavascriptJavaScript Array shift() Method

JavaScript Array shift() Method

The JavaScript Array shift() Method removes the first element of the array thus reducing the size of the original array by 1.

Syntax:

arr.shift()

Parameters: This method does not accept any parameter.

Return value: This function returns the removed first element of the array. If the array is empty then this function returns undefined.

Note: This function can also be used with other javascript objects that behave like the array.

Below is an example of the Array shift() method.

Example 1: In this example, the shift() method removes the first string element of the array, therefore it returns GFG.

JavaScript




function func() {
    // Original array
    let array = ["GFG", "Geeks", "for", "Geeks"];
 
    // Checking for condition in array
    let value = array.shift();
 
    console.log(value);
    console.log(array);
}
 
func();


Output:

GFG
Geeks, for, Geeks

Example 2: In this example, the shift() method removes the first element of the array, therefore it returns 34.

JavaScript




function func() {
 
    // Original array
    let array = [34, 234, 567, 4];
 
    // Checking for condition in array
    let value = array.shift();
 
    console.log(value);
    console.log(array);
}
func();


Output:

34
234,567,4

Example 3: In this example, the shift() method tries to remove the first element of the array, but the array is empty, therefore it returns undefined.

JavaScript




function func() {
 
    // Original array
    let array = [];
 
    // Checking for condition in array
    let value = array.shift();
 
    console.log(value);
    console.log(array);
}
func();


Output:

undefined

We have a complete list of Javascript Array methods, to check those please go through this Javascript Array Complete reference article.

Supported Browsers: The browsers supported by the JavaScript Array shift() method are listed below:

  • Google Chrome 1 and above
  • Edge 12 and above
  • Firefox 1 and above
  • Internet Explorer 5.5 and above
  • Opera 4 and above
  • Safari 1 and above

We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS