English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
shift()The method removes the first element from the array and returns it.
This method changes the length of the array.
If this method is called on an empty arrayshift(), it will returnundefined.
Note:To delete the last element of the array, usepop()Method.
array.shift()
var fruits = ["Banana", "Mango", "Apple", "Orange"]; fruits.shift();Test and see‹/›
The numbers in the table specify the first browser version that fully supports the shift() method:
Method | |||||
shift() | 1 | 1 | Is | Is | 5.5 |
Return Value: | Returns the element removed from the array |
---|---|
JavaScript Version: | ECMAScript 1 |
Theshift()The method returns the "removed" element:
var fruits = ["Banana", "Mango", "Apple", "Orange"]; var x = fruits.shift();Test and see‹/›