Deep Clone an Object

function deepClone(obj) {

  return JSON.parse(JSON.stringify(obj));

}

const original = { a: 1, b: { c: 2 } };

const clone = deepClone(original);

clone.b.c = 3;

console.log(original.b.c); // Output: 2

Leave a comment

Your email address will not be published. Required fields are marked *