The copyWithin() method of an array is used to copy the sequence of values of the array to a different position in the array.
The copyWithin() method takes three arguments: the first argument represents the target index to which copy elements the second argument represents the index position from which start copying and the third argument represents the index, that is, where copying elements should end.
The third argument is optional and if not provided then it defaults to length-1, where length is the length of the array. If startIndex is negative then it's calculated as length+startIndex. Similarly, if endIndex is negative then it's calculated as length+endIndex.
Here is an example ...