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.