copyWithIn的运行原理

let  arr1 =  ['a','b','c','d','e','f'];
function copyWithIn(arr,target,start,end){
	let copyarr  =  arr.slice(start,end);
	let i  = 0;
	arr.forEach(function(item,index){
			if(index>=target  &&  copyarr[i]){
						arr[index]  =  copyarr[i];
							i++;
				}
	})
	return  arr
}
copyWithIn(arr1,2,0,2);
  • ArrayObject.copyWithin(target,start?,end?)
  • target:开始替换的位置
  • start:开始复制的位置
  • end:结束复制的位置不包含当前下标

猜你喜欢

转载自blog.csdn.net/qq_43201542/article/details/87180787