js copy from array code example
Example 1: javascript duplicate an array
let arr =["a","b","c"];
// ES6 way
const duplicate = [...arr];
// older method
const duplicate = Array.from(arr);
Example 2: javascript copy array
// 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));