15.4.4.13 Array.prototype.unshift([item1[, item2[, ... ]]])

2010-07-05

int Array.prototype.unshift([item1:mixed[, item2:mixed[, ... ]]])

Insert given arguments at the start of this array.

The this value is coerced to an object.

Array.prototype.unshift.length = 1

Code: (Meta Ecma)
Array.prototype.unshift = function(){
var O = ToObject(this);
var lenVal = O.[[Get]]("length");
var len = ToUint32(lenVal);
var argCount = arguments.length;
var k = len;
while (k > 0) {
var from = ToString(k-1);
var to = ToString(k + argCount - 1);
var fromPresent = O.[[HasProperty]](from);
if (fromPresent) {
var fromValue = O.[[Get]](from);
O.[[put]](to, fromValue, true);
} else {
O.[[Delete]](to, true);
}
--k;
}
var j = 0;
var items = Array.prototype.slice.call(arguments);
while (items.length) {
var E = items.shift();
O.[[Put]](Tostring(j), E, true);
++j;
}
O.[[Put]]("length");
return len + argCount;
}