copyWithin()方法将数组中的元素序列复制到以target起始的位置。 副本取自第二个参数和第三个参数 start 和end的位置下标。end 参数是可选的,默认为数组长度。这个方法的算法和Array.prototype.copyWithin相同。 TypedArray 是这里的 类型化数组类型 之一。
typedarray.copyWithin(target, start[, end = this.length])
targetstartend 可选修改后的类型化数组。
更多信息请见Array.prototype.copyWithin。
这个方法取代了实验性的 TypedArray.prototype.move()。
var buffer = new ArrayBuffer(8);
var uint8 = new Uint8Array(buffer);
uint8.set([1,2,3]);
console.log(uint8); // Uint8Array [ 1, 2, 3, 0, 0, 0, 0, 0 ]
uint8.copyWithin(3,0,3);
console.log(uint8); // Uint8Array [ 1, 2, 3, 1, 2, 3, 0, 0 ]
| Specification | Status | Comment |
|---|---|---|
| ECMAScript 2015 (6th Edition, ECMA-262) TypedArray.prototype.copyWithin |
Standard | 初始定义。 |
| ECMAScript Latest Draft (ECMA-262) TypedArray.prototype.copyWithin |
Draft |
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | 45.0 | 34 (34) | 未实现 |
36.0 |
未实现 |
| Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | 未实现 | 未实现 | 34.0 (34) | 未实现 | 未实现 | 未实现 |