Export (0) Print
Expand All

shift Method (Array) (JavaScript)

Removes the first element from an array and returns it.

arrayObj.shift( )

The required arrayObj reference is an Array object.

Returns the element removed from the array.

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

Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Also supported Store apps (Windows 8 and Windows Phone 8.1). See Version Information.

Show:
© 2014 Microsoft