JavaScript shift() Method
Example
Remove elements from an array:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.shift()
fruitsOutput result:
Orange,Apple,Mango
Try it »
Definition and Usage
The shift() method is used to remove the first element from an array and return the value of that first element.
Note: This method changes the length of the array!
Tip: To remove an element from the end of an array, you can use pop() method.
Browser support





All major browsers support shift().
Syntax
array
.shift()
Return Value
| Type | Description |
|---|---|
| Any type (*****) | The value of the original first element of the array (the removed element). |
***: Array elements can be a string, number, array, boolean, or other object type.
Technical Details
| JavaScript version: | 1.2 |
|---|
JavaScript Array object