Array.shift Last updated: 19. Jan 2023

The shift() method removes the first element from an array and returns that element. This method changes the length of the array.

Parameters

This function takes no parameters

Returns

Returns the element that was removed from array.

Example

Code example (#JS)

#JS is mixed HTML (or other text file) with inline JavaScript with # starting and ending each inline statement.
#{
    // Init an array with two items
    var arr = ["one", "two"];
    
    // Remove first item with "shift"
    arr.shift();
    
    // Output the array to screen
    write(JSON.stringify(arr));
}#

Output

The #JS code above produces the output shown below:
["two"]