JavaScript Array copyWithin() method
copies array elements to another position in an array

copyWithin() method copies array elements to another position in the same array and returns this array without modifying its length.

syntax

copyWithin(target, start, end)

target The index (position) to copy the elements to.

start (optional). The start index (position). Default is 0.

end (optional). The end index (position). Default is the array length.

Negative index counts back from the end of the array.

If end implies a position before or at the position that start implies, nothing is copied.

copyWithin() method overwrites the existing values.

copyWithin() method does not add items to the array.

syntax 1 description
copy array elements to another position in myArray from start index
myArray.copyWithin(target, start)
syntax 2 description
copy array elements to another position in myArray from start index to end index
myArray.copyWithin(target, start, end)