{"ScriptPreparationCode":null,"TestCases":[{"Name":"?. operator (results in defined value)","Code":"const obj = { a: { b: { c: { exists: true } } } };\r\nconst exists = obj?.a?.b?.c?.exists;","IsDeferred":false},{"Name":"?. operator (results in undefined value)","Code":"const obj = { a: { b: { c: { exists: true } } } };\r\nconst exists = obj?.a?.b?.c?.d?.e?.f?.g?.exists;","IsDeferred":false},{"Name":"getProperty (results in defined value)","Code":"function getProperty(obj, ...path) {\r\n if (typeof obj !== \u0027object\u0027 || obj === null) {\r\n return undefined;\r\n }\r\n if (path.length === 0) {\r\n return obj;\r\n }\r\n\r\n let current = obj;\r\n for (let index = 0; index \u003C path.length; index \u002B= 1) {\r\n current = current[path[index]];\r\n\r\n // If there is more path to traverse but the current value is not traversable, quit.\r\n const isArray = Array.isArray(current);\r\n const isObject = !isArray \u0026\u0026 typeof current === \u0027object\u0027 \u0026\u0026 current !== null;\r\n if (!isObject \u0026\u0026 !isArray \u0026\u0026 (index \u002B 1) \u003C path.length) {\r\n return undefined;\r\n }\r\n }\r\n\r\n return current;\r\n}\r\n\r\nconst obj = { a: { b: { c: { exists: true } } } };\r\nconst exists = getProperty(obj, \u0027a\u0027, \u0027b\u0027, \u0027c\u0027, \u0027exists\u0027);","IsDeferred":false},{"Name":"getProperty (results in undefined value)","Code":"function getProperty(obj, ...path) {\r\n if (typeof obj !== \u0027object\u0027 || obj === null) {\r\n return undefined;\r\n }\r\n if (path.length === 0) {\r\n return obj;\r\n }\r\n\r\n let current = obj;\r\n for (let index = 0; index \u003C path.length; index \u002B= 1) {\r\n current = current[path[index]];\r\n\r\n // If there is more path to traverse but the current value is not traversable, quit.\r\n const isArray = Array.isArray(current);\r\n const isObject = !isArray \u0026\u0026 typeof current === \u0027object\u0027 \u0026\u0026 current !== null;\r\n if (!isObject \u0026\u0026 !isArray \u0026\u0026 (index \u002B 1) \u003C path.length) {\r\n return undefined;\r\n }\r\n }\r\n\r\n return current;\r\n}\r\n\r\nconst obj = { a: { b: { c: { exists: true } } } };\r\nconst exists = getProperty(obj, \u0027a\u0027, \u0027b\u0027, \u0027c\u0027, \u0027d\u0027, \u0027e\u0027, \u0027f\u0027, \u0027g\u0027, \u0027exists\u0027);","IsDeferred":false}]}