Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

JavaScript shift() Method

JavaScript shift() Method

Array Object Reference JavaScript Array object

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

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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

Array Object Reference JavaScript Array object