Array.shift

Removes the first element from an array and returns that element. This method changes the length of the array.
Method of Array

Syntax

shift()

Parameters

None.

Example

The following code displays the myFish array before and after removing its first element. It also displays the removed element:

This example produces the following results:

myFish before: ["angel", "clown", "mandarin", "sturgeon"]
myFish after: ["clown", "mandarin", "sturgeon"]
Removed this element: angel

See also

Array.pop, Array.push, Array.unshift

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.