Typed Array copyWithin()
Examples
Copy to index 2, all elements from index 0:
// Create an Array
const myArr = Int32Array.of(10,20,30,40,50,60);
myArr.copyWithin(2, 0);
Try it Yourself »
Copy to index 2, the elements from index 0 to 2:
// Create an Array
const myArr = Int32Array.of(10,20,30,40,50,60);
myArr.copyWithin(2, 0, 2);
Try it Yourself »
Description
The copyWithin()
method copies array elements to another position in an array.
The copyWithin()
method overwrites the existing values.
The copyWithin()
method does not add items to the array.
Syntax
typed-array.copyWithin(target, start, end)
typed-array must be one of the following: Int8ArrayUint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float16Array Float32Array Float64Array BigInt64Array BigUint64Array |
Parameters
Parameter | Description |
target | Required. The index (position) to copy the elements to. |
start | Optional. The start index. Default is 0. |
end | Optional. The end index. Default is the array length. |
Return Value
Type | Description |
Array | The modifyed array. |
JavaScript Typed Arrays
Browser Support
copyWithin()
is an ECMAScript6 (ES6 2015) feature.
JavaScript 2015 is fully supported in all modern browsers since June 2017:
Chrome 51 | Edge 15 | Firefox 54 | Safari 10 | Opera 38 |
May 2016 | Apr 2017 | Jun 2017 | Sep 2016 | Jun 2016 |
copyWithin()
is not supported in Internet Explorer.