English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript Array shift() Method

 JavaScript Array Object

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.

Syntax:

array.shift()
var fruits = ["Banana", "Mango", "Apple", "Orange"];
fruits.shift();
Test and see‹/›

Browser Compatibility

The numbers in the table specify the first browser version that fully supports the shift() method:

Method
shift()11IsIs5.5

Technical Details

Return Value:Returns the element removed from the array
JavaScript Version:ECMAScript 1

More examples

Theshift()The method returns the "removed" element:

var fruits = ["Banana", "Mango", "Apple", "Orange"];
var x = fruits.shift();
Test and see‹/›

 JavaScript Array Object