Share via


unshift Method

Inserts specified elements into the beginning of an array.

function unshift([item1 : Object [, ... [, itemN : Object]]]) : Array

Arguments

  • item1, ... , 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);
var s = ar.toString();
print (s);
// Output: 12,13,14,10,11

Requirements

Version 5.5

Applies To:

Array Object

See Also

Reference

shift Method

Change History

Date

History

Reason

July 2009

Modified example.

Content bug fix.

March 2009

Added example.

Information enhancement.