YouTip LogoYouTip

Jsref Copywithin

# JavaScript copyWithin() Method [![Image 3: Array Object Reference Manual](#) JavaScript Array Object](#) ## Example Copy the first two elements of the array to the last two positions: var fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.copyWithin(2, 0); _fruits_ output: Banana,Orange,Banana,Orange [Try it Β»](#) * * * ## Definition and Usage The copyWithin() method is used to copy elements from one position in an array to another position within the same array. * * * ## Browser Support The numbers in the table specify the first browser version that fully supports the method. | Method | | | | | | | --- | --- | --- | --- | --- | --- | | copyWithin() | 45.0 | 12.0 | 32.0 | 9 | 32.0 | * * * ## Syntax array.copyWithin(target, start, end) ## Parameters | Parameter | Description | | --- | --- | | _target_ | Required. The index position to copy elements to. | | _start_ | Optional. The start index from where to copy elements. | | _end_ | Optional. The end index (exclusive) up to which to copy elements (default is _array_.length). If negative, it is treated as _array_.length + _end_. | ## Technical Details Return Value: Array JavaScript Version: ECMAScript 6 ## More Examples ## Example Copy the first two elements of the array to the third and fourth positions: var fruits = ["Banana", "Orange", "Apple", "Mango", "Kiwi", "Papaya"]; fruits.copyWithin(2, 0, 2); Output: Banana,Orange,Banana,Orange,Kiwi,Papaya [Try it Β»](#) * * JavaScript Array Object](#)
← Jsref FindindexNodejs Mongodb β†’