Javascript Array copyWithin(target, start = 0, end = this.length)

Description

Javascript Array copyWithin(target, start = 0, end = this.length)

Array.prototype.copyWithin = function(target, start = 0, end = this.length) {
 let arr = this;/*from   ww w  .j  a  va 2  s.  c om*/
 let len = end - start;
 let isArray = Array.isArray(arr);
 start < 0 && (start += this.length);
 end < 0 && (end += this.length);
 for(let i = target;i < len;i++){
  if(isArray || arr[i] != void 0){
   arr[i] = arr[start];
  }
  start ++;
 }
 return arr;
}



PreviousNext

Related