15.4.4.6 Array.prototype.pop()

2010-07-05

mixed Array.prototype.pop()

Remove the last element from this array and return it.

The this object will be coerced into an object.

Calling this on an empty array will force the length property to 0 and returns undefined.

Code: (Meta Ecma)
Array.prototype.pop = function(){
var O = ToObject(this);
var lenVal = O.[[Get]]("length");
var len = ToUint32(lenVal);
if (len == 0) {
O.[[Put]]("length", 0);
return undefined;
}
var indx = ToString(len-1);
var element = O.[[Get]](indx);
O.[[Delete]](indx, true);
O.[[Put]]("length", indx, true);
return element;
}