shift Method (Array) (JavaScript)

Removes the first element from an array and returns it.

Syntax


arrayObj.shift( )  

Parameters

The required arrayObj reference is an Array object.

Return Value

Returns the element removed from the array.

Remarks

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  

Requirements

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.

See Also

unshift Method (Array)