JSON.parse(JSON.stringify(object))
//Using JSON stringify function
var obj2 = JSON.parse(JSON.stringify(obj));
//Using lodash deep clone method
var obj2 = _.cloneDeep(obj, true);
//Angular framework comes with angular.copy function
var obj2 = angular.copy(obj);
// Using jQuery extend function
var obj2 = $.extend(true, {}, obj);
// Create an object with a value and a circular reference to itself.
const original = { name: "MDN" };
original.itself = original;
// Clone it
const clone = structuredClone(original);
console.assert(clone !== original); // the objects are not the same (not same identity)
console.assert(clone.name === "MDN"); // they do have the same values
console.assert(clone.itself === clone); // and the circular reference is preserved
const obj1 = { a: 1, b: 2, c: 3 };
// this converts the object to string so there will be no reference from
// this first object
const s = JSON.stringify(obj1);
const obj2 = JSON.parse(s);