1const obj1 = { a: 1, b: 2, c: 3 };
2// this converts the object to string so there will be no reference from
3// this first object
4const s = JSON.stringify(obj1);
5
6const obj2 = JSON.parse(s);
1const deepCopyFunction = (inObject) => {
2 let outObject, value, key
3
4 if (typeof inObject !== "object" || inObject === null) {
5 return inObject // Return the value if inObject is not an object
6 }
7
8 // Create an array or object to hold the values
9 outObject = Array.isArray(inObject) ? [] : {}
10
11 for (key in inObject) {
12 value = inObject[key]
13
14 // Recursively (deep) copy for nested objects, including arrays
15 outObject[key] = deepCopyFunction(value)
16 }
17
18 return outObject
19}