let arr =["a","b","c"];
// ES6 way
const copy = [...arr];
// older method
const copy = Array.from(arr);
const sheeps = ['Apple', 'Banana', 'Juice'];
// Old way
const cloneSheeps = sheeps.slice();
// ES6 way
const cloneSheepsES6 = [...sheeps];
var numbers = [1,2,3,4,5];
var newNumbers = Object.assign([], numbers);
// this is for array with complex object
var countries = [
{name: 'USA', population: '300M'},
{name: 'China', population: '1.6B'}
];
var newCountries = JSON.parse(JSON.stringify(countries));
// Copy an array
fn main() {
let arr = ["a","b","c"];
let mut another = arr.clone(); // make a copy
println!("copy of arr = {:?} ", another);
another[1] = "d"; // make a change
assert_eq!(arr, another); // panic, no longer equal
}
let shallowCopy = fruits.slice() // this is how to make a copy
// ["Strawberry", "Mango"]
let arr = ['a','b','c'];
const duplicate = [...arr];
console.log(duplicate);