English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript Array copyWithin() Method

 JavaScript Array Object

copyWithin()The method copies a part of the array to another position in the same array and returns it without modifying its size.

Syntax:

array.copyWithin(target, start, end)
var array1 = [1, 2, 3, 4, 5];
array1.copyWithin(0, 3, 4);
Test and see‹/›

Browser Compatibility

The numbers in the table specify the first browser version that fully supports the copyWithin() method:

Method
copyWithin()453232912

Parameter Value

ParameterDescription
targetThe index position to copy elements to
startThe index position to start copying elements from (this is optional)
endThe index position to stop copying elements from (this is optional)

Technical Details

Return Value:Modified Array
JavaScript Version:ECMAScript 6

More Examples

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‹/›

 JavaScript Array Object