copyWithin

语法

Array.prototype.copywithin(index, startIndex, endIndex)

  index

    复制的数组项开始替换的起始索引值

  start

    复制的数组项的起始位置

  end

    复制的数组项的结束位置(不包含)

应用

  删除数组中某一项

[].copyWithin(index, index + 1).pop()

  置顶数组某一项

Array.prototype.top = function(index) {
    const value = this[index]
    this.copyWithin(1, 0, index)
    this[0] = value
}

  

posted @ 2023-01-29 23:06  671_MrSix  阅读(9)  评论(0编辑  收藏  举报