ES6 - Math.trunc()
此函数将数组的一部分浅拷贝到同一数组中的另一个位置,并在不修改其长度的情况下返回它。
语法
以下语法适用于数组方法 ".copyWithin()",其中,
target − 从零开始的索引,将序列复制到该索引。如果为负数,则从末尾开始计算目标。
start − 这是一个可选参数。从零开始的索引,开始复制元素。如果为负数,则从末尾开始计算开始。如果省略开始,copyWithin 将从索引 0 开始复制。
end − 这是一个可选参数。从零开始的索引处结束复制元素。copyWithin 复制到结束处但不包括结束处。如果为负数,则从结束处开始计算。如果省略结束,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(clusive) console.log(marks.copyWithin(2,4))//destination,source start,(till length) </script>
上述代码的输出将如下所示 −
[30, 40, 30, 40, 50, 60] [30, 40, 50, 60, 50, 60]