Sunny-117 / js-challenges

✨✨✨ Challenge your JavaScript programming limits step by step

Home Page:https://juejin.cn/column/7244788137410560055

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Array.prototype.push

Sunny-117 opened this issue · comments

Array.prototype.myPush = function (...arg) {
  for (let i = 0; i < arg.length; i++) {
    this[this.length] = arg[i];
  }        
  return this.length;
};
commented
Array.prototype.Mypush = function(){
    var args = [...arguments]
    args.map(item => {
        this[this.length] = item;
    })
    return this.length;
}
Array.prototype.push = function() {
  var itemsToAdd = arguments.length;
  var len = this.length;
  for (var i = 0; i < itemsToAdd; i++) {
    this[len + i] = arguments[i];
  }
  return this.length;
};