JavaScript TypedArray copyWithin() Method
The copyWithin() method copies the sequence of array within the array and set a new starting point at target. The copyWithin() method is a mutable method and update the array directly. It does not alter the length of array, but will change its content and create new properties if necessary. This method have three parameters, two mandatory and one optional.
Syntax:
Parameters:
Target: The index position to copy the elements to. (Required).
Start: The index position elements are started copying from. (Optional)
End: It is optional. Source end index position where to end copying elements from.
Return value:
The modified array.
Browser Support:
Chrome | 45.0 |
Edge | 12.0 |
Firefox | 32.0 |
Opera | NO |
Example 1
JavaScript TypedArray copyWithin(target) Method
Output:
1,2,1,2,3,4,5,6,7,8
Example 2
JavaScript TypedArray copyWithin(target,start) Method
Output:
1,2,4,5,6,7,8,9,10,10
Example 3
JavaScript TypedArray copyWithin(target,start,end ) Method
Output:
1,3,4,4,5,6,7,8,9,10