{"ScriptPreparationCode":"function flattenKeys(s) {\r\n return s.replace(/\\[(\\w\u002B)\\]/g, \u0027.$1\u0027).replace(/^\\./, \u0027\u0027).split(\u0027.\u0027)\r\n}\r\n\r\nvar testA = {\r\n a: {\r\n b: {\r\n c: {\r\n d: [{\r\n sample1: \u0027sample1\u0027,\r\n sample2: {\r\n sample3: {\r\n sample4: \u0027sample4\u0027\r\n }\r\n }\r\n }, {\r\n otherSample1: \u0027otherSample1\u0027,\r\n otherSample2: {\r\n otherSample3: {\r\n otherSample4: \u0027otherSample4\u0027\r\n }\r\n }\r\n }]\r\n }\r\n }\r\n }\r\n};\r\n\r\nfunction omit3(obj, props) {\r\n if (typeof props == \u0022string\u0022) {\r\n props = [props];\r\n }\r\n if (obj != null \u0026\u0026 obj != undefined \u0026\u0026 typeof obj == \u0027object\u0027) {\r\n const newObj = JSON.parse(JSON.stringify(obj)); \r\n for (const i in props) {\r\n const path = flattenKeys(props[i]);\r\n if (path.length == 1) {\r\n if (typeof newObj == \u0027object\u0027) {\r\n if (Array.isArray(newObj) \u0026\u0026 newObj?. [props[i]] != null) {\r\n newObj?.splice(props[i], 1);\r\n } else {\r\n delete newObj?. [props[i]];\r\n }\r\n }\r\n } else if (path.length \u003E 1) {\r\n if (newObj[path[0]] != null) {\r\n newObj[path[0]] = omit3(newObj?. [path[0]], [path.slice(1).join(\u0027.\u0027)]);\r\n }\r\n }\r\n }\r\n return newObj;\r\n }\r\n return obj;\r\n}\r\n \r\nfunction omit2(obj, props) {\r\n if (typeof props == \u0022string\u0022) {\r\n props = [props];\r\n }\r\n if (obj != null \u0026\u0026 obj != undefined \u0026\u0026 typeof obj == \u0027object\u0027) {\r\n const newObj = structuredClone(obj);\r\n for (const i in props) {\r\n const path = flattenKeys(props[i]);\r\n if (path.length == 1) {\r\n if (typeof newObj == \u0027object\u0027) {\r\n if (Array.isArray(newObj) \u0026\u0026 newObj?. [props[i]] != null) {\r\n newObj?.splice(props[i], 1);\r\n } else {\r\n delete newObj?. [props[i]];\r\n }\r\n }\r\n } else if (path.length \u003E 1) {\r\n if (newObj[path[0]] != null) {\r\n newObj[path[0]] = omit2(newObj?. [path[0]], [path.slice(1).join(\u0027.\u0027)]);\r\n }\r\n }\r\n }\r\n return newObj;\r\n }\r\n return obj;\r\n}\r\n \r\n","TestCases":[{"Name":"lodash omit","Code":"const resultA = _.omit(testA, [\u0027a.b.c.d\u0027]);\r\nconst resultB = _.omit(testA, [\u0027a.b.c.d[1].otherSample2.otherSample3\u0027]);","IsDeferred":false},{"Name":"plain omit (structuredClone)","Code":"\r\nconst resultA = omit2(testA, [\u0027a.b.c.d\u0027]);\r\nconst resultB = omit2(testA, [\u0027a.b.c.d[1].otherSample2.otherSample3\u0027]);","IsDeferred":false},{"Name":"plain omit (JSON.stringify)","Code":"\r\nconst resultA = omit3(testA, [\u0027a.b.c.d\u0027]);\r\nconst resultB = omit3(testA, [\u0027a.b.c.d[1].otherSample2.otherSample3\u0027]);","IsDeferred":false}]}