JavaScript Array shift() Method

Definition and Usage

shift() The method removes the first item of the array.

Note:shift() The method will change the length of the array.

Note:shift The return value of the method is the removed item.

Note:shift() The method will change the original array.

Tip:To delete the last item of the array, please use pop() Method.

Instance

Example 1

Delete the first item in the array:

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.shift();

Try It Yourself

Example 2

Array.shift() returns the removed array element:

const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.shift();   // Returns "Banana"

Try It Yourself

Syntax

array.shift()

Parameters

No parameters.

Technical Details

Return Value:

Any type *, indicates the array item that has been removed.

* Array items can be strings, numbers, arrays, boolean values, or any other object types allowed in arrays.

JavaScript Version: ECMAScript 1

Browser Support

All browsers fully support shift() Method:

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Support Support Support Support Support Support

Related Pages

Tutorial:JavaScript Array

Tutorial:JavaScript Array Const

Tutorial:JavaScript Array Methods

Tutorial:JavaScript Sorting Array

Tutorial:JavaScript Array Iteration

Manual:JavaScript Array push() Method

Manual:JavaScript Array pop() Method

Manual:JavaScript Array unshift() Method