The copyWithin() method is represented by the following syntax:
target - The position where the copied element takes place.
start - It is optional. It represents the index from where the method starts copying elements. By default, it is 0.
end - It is optional. It represents the index at which elements stops copying. By default, it is array.length-1.
The modified array.
Let's see some examples of copyWithin() method.
Here, we will pass the target, start and end index with the method.Test it Now
Let's see one more example where we will copy two elements.Test it Now
In this example, we will provide only the target index and start index.Test it Now
In this example, we will provide target index only.Test it Now