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.copy

Sunny-117 opened this issue · comments

commented
Array.prototype.copy = function () {
    return [...this, ...this]
}
console.log([1, 2, 3, 4, 5].copy());
Array.prototype.copy = function() {
  var len = this.length;
  var arrCopy = new Array(len);
  for (var i = 0; i < len; i++) {
    arrCopy[i] = this[i];
  }
  return arrCopy;
};