Deep Cloning (JSON.parse + JSON.stringify)
const obj = {
name: "Joe",
address: { city: "X" },
};
const clone = JSON.parse(JSON.stringify(obj));
Copying using spread operator or Object.assign() makes a shallow copy (i.e, nested arrays & objects reference is copied instead of their values...
codedrops.hashnode.dev1 min read