Latest web development tutorials

JavaScript shift () method

Array Object Reference JavaScript Array Object

Examples

Remove from the array elements:

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

fruits resulting output:

Orange,Apple,Mango

try it"


Definition and Usage

shift () method for the first element of the array from which to remove and return the value of the first element.

NOTE: This method changes the length of the array!

Tip: Remove the end of the array elements can use pop () method.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support shift ().


grammar

array .shift ()

return value

Types of description
Any type (*) The original value of the first array element (element that was removed).

*: Array element can be a string, number, array, Boolean, or other object types.

technical details

JavaScript version: 1.2


Array Object Reference JavaScript Array Object