The Javascript TypedArray copyWithin() method is used to copy a portion of an array to another location in the same array and returns the size without modification.
Syntax:
arr.copyWithin(target) arr.copyWithin(target, start) arr.copyWithin(target, start, end)
Parameters:
target: It represents the index position at which elements to be copied.
start: It represents the index position from where elements are started copying.
end: It represents the index position to which elements have to be copied.
Returns:
Size of the array without modification.
Example 1:
<!DOCTYPE html> <html> <body> <script type="text/javascript"> var set = [11,22,33,44,55,66,77,88,99,110]; set.copyWithin(4) document.write(set); </script> </body> </html>
Example 2:
<!DOCTYPE html> <html> <body> <script type="text/javascript"> const testArray = new Uint8Array([ 11,32, 73, 24, 15, 56, 27, 18 ]); testArray.copyWithin(4, 1, 3); document.write(testArray); </script> </body> </html>