1let arr =["a","b","c"];
2// ES6 way
3const copy = [...arr];
4
5// older method
6const copy = Array.from(arr);
1const sheeps = ['Apple', 'Banana', 'Juice'];
2
3// Old way
4const cloneSheeps = sheeps.slice();
5
6// ES6 way
7const cloneSheepsES6 = [...sheeps];
1/* Copying arrays or parts of arrays in JavaScript */
2
3var fruit = ["apple", "banana", "fig"]; // Define initial array.
4console.log(fruit); // ["apple", "banana", "fig"]
5
6// Copy an entire array using .slice()
7var fruit2 = fruit.slice();
8console.log(fruit2); // ["apple", "banana", "fig"]
9
10// Copy only two array indicies rather than all three
11// From index 0 (inclusive) to index 2 (noninclusive)
12var fruit3 = fruit.slice(0,2);
13console.log(fruit3); // ["apple", "banana"]
1var oldColors=["red","green","blue"];
2var newColors = oldColors.slice(); //make a clone/copy of oldColors