The copyWithin() method copies part of an array to the same array and returns it, without modifying its.
Syntax:
list.copyWithin(target[, start[, end]])
Field of application: When we need to copy the contents of any directory to the same array at the same time, we use array.copyWithin () in javaScript.
The CopyWithin function is a variable method. The array length does not change.
Examples
var list = ["john", "alice", "oliver", "sasha"];
console.log(list.copyWithin(0,1))
output:
[“alice”, “oliver”, “sasha”, “sasha”]
var list = ["john", "alice", "oliver", "sasha"];
console.log(list.copyWithin(1,2))
output:
[“john”, “oliver”, “sasha”, “sasha”]
var list = ["john", "alice", "oliver", "sasha"];
console.log(list.copyWithin(2,3))
output:
[“john”, “alice”, “sasha”, “sasha”]