ES6 - Math.trunc()



此函数将数组的一部分浅拷贝到同一数组的另一个位置,并返回该数组而不修改其长度。

语法

下面语句的语法针对数组方法“.copyWithin()”,其中,

  • target − 要将序列复制到的从零开始的索引。如果为负,target 将从末尾开始计算。

  • start − 这是可选参数。从该从零开始的索引开始复制元素。如果为负,start 将从末尾开始计算。如果省略 start,copyWithin 将从索引 0 开始复制。

  • end − 这是可选参数。在该从零开始的索引结束复制元素。copyWithin 将向上复制,但不包括 end。如果为负,end 将从末尾开始计算。如果省略 end,copyWithin 将一直复制到最后一个索引。

arr.copyWithin(target[, start[, end]])

示例

<script>
   //copy with in
   let marks = [10,20,30,40,50,60]
   console.log(marks.copyWithin(0,2,4)) //destination,source start,source end(excluding)
   console.log(marks.copyWithin(2,4))//destination,source start,(till length)
</script>

以上代码的输出如下所示 −

[30, 40, 30, 40, 50, 60]
[30, 40, 50, 60, 50, 60]
广告
© . All rights reserved.