JavaScript Array copyWithin()

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. The default is 0. It is optional.
end: It represents the index position to end copying elements. The 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>