Copies a section of the typed array from the start index to the end index into the target index, overwriting the existing array elements starting at the target index. It modifies the original array without resizing it, and returns it.
copyWithin(target, start?, end?)
target
The target index: where to copy the section of the array.
If negative, it is treated as length + target where length is the length of the array.
start optional
The start index of the section to copy.
If start negative, it is treated as length + start. If end is negative, it is treated as length + end. If start is omitted, it is considered to be 0.
end optional
The end index of the section to copy. The section to copy doesn’t include the element at the end index.
If end is omitted, it is considered to be the length of the array.
The modified original array.
new Int16Array([0, 1, 2, 3, 4]).copyWithin(0, 2, 4)
Int16Array [2, 3, 2, 3, 4]