JavaScript shift()Method
Examples
Remove elements from an array:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.shift()
fruits.shift()
fruitsOutput:
Orange,Apple,Mango
Try it Yourself »
Definition and Usage
The shift() method is used to remove the first element of an array and return the value of the first element.
Note:This method changes the length of the array!
Tip:To remove an element from the end of the array, you can use thepop()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 |
|---|
Other Extensions
JavaScript Array Object