array klon sudut tanpa referensi
const myClonedArray = Object.assign([], myArray);
2 Programmers 1 Bug
const myClonedArray = Object.assign([], myArray);
var tempArray = JSON.parse(JSON.stringify(mainArray));
const sheeps = ['Apple', 'Banana', 'Juice'];
// Old way
const cloneSheeps = sheeps.slice();
// ES6 way
const cloneSheepsES6 = [...sheeps];
// 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));
const myClonedObject = Object.assign({}, myObject);