This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

shift

Summary

Removes the first element from an array and returns it.

Syntax

shift( )

Return Value

Returns the element removed from the array.

Examples

The following example illustrates the use of the shift method.

var arr = new Array(10, 11, 12);
 while (arr.length > 0)
     {
     var i = arr.shift();
     document.write (i.toString() + " ");
     }

 // Output:
 // 10 11 12

See also

Specification

15.4.4.9 Array.prototype.shift ( ) ECMAScript® Language Specification Standard ECMA-262 5.1 Edition / June 2011

Attributions

  • Microsoft Developer Network: Article