JavaScript Array copyWithin() method

The JavaScript array copyWithin() method is used to copy the part of the given array with its own elements and returns the modified array.

Syntax:

array.copyWithin (target, start, end)

Parameters:
target: It represents the index position where the elements will copied. It is Required.
start: It represents the index position to start copying elements from. Default is 0. It is optional.
end: It represents the index position to end copying elements. Default is array.length. It is optional.

Returns:
Modified Array.

Example:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>  
var a = ["GOLD","SILVER","DIAMOND","RUBY","PLATINUM"]   
var result = a.copyWithin(1,2,4);  
document.writeln(result);  
</script>  
</body>
</html>

Output:

GOLD,DIAMOND,RUBY,RUBY,PLATINUM
Please Share