JavaScript Array shift() Method

Definition and Usage

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

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

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

Note:shift() The method changes the original array.

Tip:To delete the last item of the array, 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()

Parameter

No parameters.

Technical Details

Return Value:

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

* 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

Panduan:JavaScript Array

Panduan:JavaScript Array Const

Panduan:JavaScript Array Method

Panduan:JavaScript Sorting Array

Panduan:Iterasi Array JavaScript

Panduan:Metode push() Array JavaScript

Panduan:Metode pop() Array JavaScript

Panduan:Metode unshift() Array JavaScript