{"ScriptPreparationCode":"var obj = {\r\n a: \u0022hello\u0022,\r\n c: \u0022test\u0022,\r\n num: 3,\r\n arr: [1, 2, 3, 4],\r\n anotherObj: {\r\n a: 35,\r\n str: \u0022tester\u0022\r\n }\r\n};\r\n\r\nfunction altClone(obj) {\r\n if (obj) {\r\n let clone;\r\n const isNested = (item) =\u003E typeof item === \u0027object\u0027;\r\n if (Array.isArray(obj)) {\r\n clone = [];\r\n obj.forEach((value) =\u003E {\r\n clone.push(isNested(value) ? deepClone(value) : value);\r\n });\r\n } else {\r\n clone = {};\r\n Object.keys(obj).forEach((key) =\u003E {\r\n const value = obj[key];\r\n clone[key] = isNested(value) ? deepClone(value) : value;\r\n });\r\n }\r\n return clone;\r\n }\r\n return obj;\r\n};\r\n\r\nvar deepClone = function(obj) {\r\n var out = null;\r\n\r\n if (Array.isArray(obj)) {\r\n out = [];\r\n for (var index = 0; index \u003C obj.length; \u002B\u002Bindex) {\r\n var subArray = obj[index];\r\n out.push((typeof subArray === \u0027object\u0027) ? deepClone(subArray) : subArray);\r\n }\r\n } else {\r\n out = {};\r\n for (var key in obj) {\r\n var subObject = obj[key];\r\n out[key] = (typeof subObject === \u0027object\u0027) ? deepClone(subObject) : subObject;\r\n }\r\n }\r\n return out;\r\n};\r\n\r\nfunction structured(value) {\r\n return window.structuredClone(value)\r\n}\r\n\r\nfunction cloneArray(value) {\r\n var newArray;\r\n if (value \u0026\u0026 value.length) {\r\n newArray = [];\r\n for (var i = 0; i \u003C value.length; i\u002B\u002B) {\r\n if (typeof value[i] === \u0027object\u0027) {\r\n newArray[i] = Array.isArray(value[i]) ? cloneArray(value[i]) : cloneObject(value[i]);\r\n } else {\r\n newArray[i] = value[i];\r\n }\r\n }\r\n } else if (value === null) {\r\n newArray = null;\r\n }\r\n return newArray;\r\n}\r\n\r\nfunction cloneObject(value) {\r\n var newObject;\r\n if (value \u0026\u0026 typeof value === \u0027object\u0027 \u0026\u0026 Object.keys(value).length \u003E 0) {\r\n newObject = {};\r\n for (var key in value) {\r\n if (typeof value[key] === \u0027object\u0027) {\r\n newObject[key] = Array.isArray(value) ? cloneArray(value[key]) : cloneObject(value[key]);\r\n } else {\r\n newObject[key] = value[key];\r\n }\r\n }\r\n } else if (value \u0026\u0026 typeof value === \u0027object\u0027 \u0026\u0026 Object.keys(value).length === 0) {\r\n newObject = {};\r\n } else if (value === null) {\r\n newObject = null;\r\n }\r\n return newObject;\r\n}\r\n\r\nfunction reduceDeepClone(obj) {\r\n return Object.keys(obj).reduce((v, d) =\u003E Object.assign(v, {\r\n [d]: (obj[d].constructor === Object) ? reduceDeepClone(obj[d]) : obj[d]\r\n }), {});\r\n}","TestCases":[{"Name":"Lodash cloneDeep","Code":"testCopy = _.cloneDeep(obj);","IsDeferred":false},{"Name":"JSON parse","Code":"testCopy = JSON.parse(JSON.stringify(obj));","IsDeferred":false},{"Name":"For loop ","Code":"testCopy = cloneObject(obj);","IsDeferred":false},{"Name":"Recursive clone deep","Code":"testCopy = deepClone(obj);","IsDeferred":false},{"Name":"Recursive reduce clone deep","Code":"testCopy = reduceDeepClone(obj);","IsDeferred":false},{"Name":"altClone","Code":"testCopy = altClone(obj);","IsDeferred":false},{"Name":"structured","Code":"testCopy = structured(obj);","IsDeferred":false}]}