Array Copies in JavaScript
Let's learn how to copy arrays. As an example, let's have some array:
let arr = [1, 2, 3, 4, 5];
Let's make a copy of it. This is done using a special method, like this:
let copy = Object.assign([], arr);
There is also a second approach - via destructuring:
let copy = [...arr];