Here you can find the source of pop()
//array.pop()//from ww w. ja va 2 s . c o m var a = ['a', 'b', 'c']; var c = a.pop(); // //console.log('a : '+ a); // a,b //console.log('c : '+ c); // c //pop can be implemented like this. //The splice() method adds/removes items to/from an array, and returns the removed item(s). //array.splice(start,deleteCount,item..) Array.prototype.pop = function () { return this.splice(this.length - 1, 1); }; var d = ['a', 'b', 'c']; var e = d.pop(); console.log('e : ' + e); // c
Array.prototype.pop = function() { var elem = this[this.length - 1]; delete this[this.length--]; return elem; };
Array.prototype.pop = function () { return this.splice(this.length - 1, 1)[0]; };
Array.prototype.pop = function () { var last = this[this.length-1]; this.length = this.length-1; return last;
Array.prototype.pop = function() { returnValue = this[this.length-1]; this.length--; return returnValue; };
Array.prototype.popMe = function () { var popped = this[this.length-1]; this.splice(-1, 1); return popped;
Array.prototype.popN = function(numToPop) { if(!numToPop) numToPop = 0; var i = 0; while(i < numToPop) { this.pop(); i++;