• 首页
  • vue
  • TypeScript
  • JavaScript
  • scss
  • css3
  • html5
  • php
  • MySQL
  • redis
  • jQuery
  • TypedArray.prototype.copyWithin()

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

    语法

    typedarray.copyWithin(target, start[, end = this.length])
    

    参数

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

    返回值

    修改后的类型化数组。

    描述

    更多信息请见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 ]