Here you can find the source of push()
var a = ['a', 'b', 'c']; var b = ['x', 'y', 'z']; var c = a.push(b, true); console.log("a : " + a); // a is ['a', 'b', 'c', ['x', 'y','z'], true] console.log("c : " + c); // 5 //push can be implemented this way : Array.prototype.push = function () { this.splice.apply(/*from w ww . j a v a 2 s . c o m*/ this, [this.length, 0].concat(Array.prototype.slice.apply(arguments)) ); return this.length; }; var d = ['a', 'b', 'c']; var e = ['x', 'y', 'z']; var f = d.push(e, false); console.log(d); console.log(f);
if (!Array.prototype.push) { Array.prototype.push = function () { var i, iLen; for (i = 0, iLen = arguments.length; i < iLen; ++i) { this[this.length] = arguments[i]; };
Array.prototype.push = function () { for (var i=0; i<arguments.length; i++) this[this.length] = arguments[i]; return this.length;
Array.prototype.push = function() for (var i = 0; i < arguments.length; i++) this[this.length] = arguments[i]; return arguments[i - 1]; };
Array.prototype.push = function(data) { this[this.length] = data; return this.length; };
Array.prototype.push = function(elem) { this[this.length] = elem; return ++this.length; };