首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

typedArray.copyWithin

copyWithin()方法将数组中的元素序列复制到以target起始的位置。 副本取自第二个参数和第三个参数startend的位置下标。end参数是可选的,默认为数组长度。这个方法的算法和Array.prototype.copyWithin相同。TypedArray是这里的类型化数组类型之一。

语法

代码语言:javascript
复制
typedarray.copyWithin(target, start[, end = this.length])

参数

target目标起始位置的下标,复制元素到这里。start源起始位置的下标,在这里开始复制元素。end可选可选。源终止位置的下标,在这里停止复制元素。

返回值

修改后的类型化数组。

描述

更多信息请见Array.prototype.copyWithin

这个方法取代了实验性的TypedArray.prototype.move()

示例

代码语言:javascript
复制
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)The definition of 'TypedArray.prototype.copyWithin' in that specification.

Standard

Initial definition.

ECMAScript 2017 Draft (ECMA-262)The definition of 'TypedArray.prototype.copyWithin' in that specification.

Draft

?

浏览器兼容性

Feature

Chrome

Firefox (Gecko)

Internet Explorer

Opera

Safari

Basic support

45.0

34 (34)

No support

36.0

No support

Feature

Android

Chrome for Android

Firefox Mobile (Gecko)

IE Mobile

Opera Mobile

Safari Mobile

Basic support

No support

No support

34.0 (34)

No support

No support

No support

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com