Skip to content

Latest commit

 

History

History
32 lines (18 loc) · 702 Bytes

第九课 ES6中的数组拓展之copyWithin.md

File metadata and controls

32 lines (18 loc) · 702 Bytes

ES6中的数组拓展之copyWithin

作用类似于合并数组,载体数组 + 被合并数组的一部分(可指定合并数组的长度及内容)

参数设置

当前数组.copyWithin(替换数据位,复制数据位, 个数)

1)当前数组

被作用的数组

2)替换数据位

将数据替换至目标数组的索引位(不可缺省)

3)起始位置

从数组的第索引位开始复制(用于放置到替换数据位/可以缺省)

4)结尾位置

结束索引位置(不包含本位置)(可以缺省)

实例

let arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
arr.copyWithin(2, 0, 2);
console.log(arr); // ["a", "b", "a", "b", "e", "f", "g"]