JavaScript copyWithin() 方法
实例
将前两个数组元素复制到最后两个数组元素:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.copyWithin(2, 0);
fruits 输出结果:
['Banana', 'Orange', 'Banana', 'Orange']
尝试一下 »
定义和用法
copyWithin() 方法将数组元素复制到数组中的另一个位置,覆盖现有值。
copyWithin() 方法永远不会向数组添加更多项。
提示:copyWithin() 方法会覆盖原始数组。
浏览器支持
注释:Internet Explorer 不支持 copyWithin() 方法。
语法
array.copyWithin(target, start, end)
参数值
| 参数 | 描述 |
|---|---|
| target | 必需。将元素复制到的索引位置。
|
| start | 可选。开始复制元素的索引位置(默认为 0)。
|
| end | 可选。停止从中复制元素的索引位置(默认为 array.length)。
|
返回值
| Type | 描述 |
|---|---|
| Array 对象 | 数组,被改变的数组。
|
技术细节
| JavaScript 版本: | ECMAScript 6
|
|---|

免费 AI IDE

JavaScript Array 对象
更多建议: