Deep clone of multi-level object
let obj = {x: 20, y: {z: 30}};
//long version
const makeDeepClone = (obj) => {
let newObject = {};
Object.keys(obj).map(key => {
if(typeof obj[key] === 'object'){
newObject[key] = make DeepClone(obj[key]);
} else {
newObject[key] = obj[key];
}
});
return neObject;
}
const cloneObj = makeDeepClone(obj);
//Shorthand
const cloneObj = JSON.parse(JSON.stringify(obj));