English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
copyWithin()The method copies a part of the array to another position in the same array and returns it without modifying its size.
array.copyWithin(target, start, end)
var array1 = [1, 2, 3, 4, 5]; array1.copyWithin(0, 3, 4);Test and see‹/›
The numbers in the table specify the first browser version that fully supports the copyWithin() method:
Method | |||||
copyWithin() | 45 | 32 | 32 | 9 | 12 |
Parameter | Description |
---|---|
target | The index position to copy elements to |
start | The index position to start copying elements from (this is optional) |
end | The index position to stop copying elements from (this is optional) |
Return Value: | Modified Array |
---|---|
JavaScript Version: | ECMAScript 6 |
If the parameter is a negative number, the target is calculated from the end:
var array1 = [1, 2, 3, 4, 5]; array1.copyWithin(-2);Test and see‹/›