unshift Method (Array) (JavaScript)

Inserts new elements at the start of an array.

Syntax


arrayObj.unshift([item1[, item2 [, . . . [, itemN]]]])  

Parameters

arrayObj
Required. An Array object.

item1, item2,. . ., itemN
Optional. Elements to insert at the start of the Array.

Remarks

The unshift method inserts elements into the start of an array, so they appear in the same order in which they appear in the argument list.

Example

The following example illustrates the use of the unshift method.

var ar = new Array();  
ar.unshift(10, 11);  
ar.unshift(12, 13, 14);  
document.write(ar.toString());  

// Output: 12,13,14,10,11  

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

shift Method (Array)