{"ScriptPreparationCode":"var obj = {a: \u0022hello\u0022, c: \u0022test\u0022, num: 3, arr: [1, 2, 3, 4], anotherObj: {a: 35, str: \u0022tester\u0022}};\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\n function 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\n function 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}]}