{"ScriptPreparationCode":"var testArray = [{\r\n description: \u0027Random description.\u0027,\r\n testNumber: 123456789,\r\n testBoolean: true,\r\n testObject: {\r\n testString: \u0027test string\u0027,\r\n testNumber: 12345\r\n },\r\n testArray: [{\r\n myName: \u0027test name\u0027,\r\n myNumber: 123245\r\n }]\r\n},{\r\n description: \u0027Random description.\u0027,\r\n testNumber: 123456789,\r\n testBoolean: true,\r\n testObject: {\r\n testString: \u0027test string\u0027,\r\n testNumber: 12345\r\n },\r\n testArray: [{\r\n myName: \u0027test name\u0027,\r\n myNumber: 123245\r\n }]\r\n}];\r\n\r\nvar testCopy = null;\r\n\r\nvar deepClone = function(obj) {\r\n var out;\r\n if (Array.isArray(obj)) {\r\n out = [];\r\n for (var index = 0; index \u003C obj.length; \u002B\u002Bindex) {\r\n let subArray = obj[index];\r\n out.push((subArray === null) ? subArray : (subArray instanceof Date) ? new Date(subArray.valueOf()) : (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] = subObject === null ? subObject : subObject instanceof Date ? new Date(subObject.valueOf()) : (typeof subObject === \u0027object\u0027) ? deepClone(subObject) : subObject;\r\n \r\n \r\n }\r\n }\r\n return out;\r\n};\r\n\r\n\r\nfunction clone(obj) {\r\n var copy;\r\n\r\n // Handle the 3 simple types, and null or undefined\r\n if (null == obj || \u0022object\u0022 != typeof obj) return obj;\r\n\r\n // Handle Date\r\n if (obj instanceof Date) {\r\n copy = new Date();\r\n copy.setTime(obj.getTime());\r\n return copy;\r\n }\r\n\r\n // Handle Array\r\n if (obj instanceof Array) {\r\n copy = [];\r\n for (var i = 0, len = obj.length; i \u003C len; i\u002B\u002B) {\r\n copy[i] = clone(obj[i]);\r\n }\r\n return copy;\r\n }\r\n\r\n // Handle Object\r\n if (obj instanceof Object) {\r\n copy = {};\r\n for (var attr in obj) {\r\n if (obj.hasOwnProperty(attr)) copy[attr] = clone(obj[attr]);\r\n }\r\n return copy;\r\n }\r\n\r\n throw new Error(\u0022Unable to copy obj! Its type isn\u0027t supported.\u0022);\r\n}","TestCases":[{"Name":"Lodash cloneDeep","Code":"testCopy = _.cloneDeep(testArray);","IsDeferred":false},{"Name":"Native map deep slice(turns objects into arrays)","Code":"testCopy = testArray.map(arr =\u003E testArray.slice());","IsDeferred":false},{"Name":"Native JSON parse","Code":"testCopy = JSON.parse(JSON.stringify(testArray));","IsDeferred":false},{"Name":"Native map deep slice at 0(turns objects into arrays)","Code":"testCopy = testArray.map(arr =\u003E testArray.slice(0));","IsDeferred":false},{"Name":"Native map(shallow clone)","Code":"testCopy = testArray.map(arr =\u003E arr);","IsDeferred":false},{"Name":"Recursive deep clone","Code":"testCopy = deepClone(testArray);","IsDeferred":false},{"Name":"Map deep clone","Code":"testCopy = testArray.map(arr =\u003E deepClone(arr));","IsDeferred":false},{"Name":"Object.assign shallow clone","Code":"testCopy = Object.assign([...testArray]);","IsDeferred":false},{"Name":"Native Map with clone function (Deep)","Code":"testCopy = testArray.map(item =\u003E clone(item));","IsDeferred":false}]}