Get Value from Object by Path
SoftServe
Write a function getValueByPath(obj, path) that takes an object and a path string (e.g., "a.b.c") and returns the value at that path.
If the path doesn't exist, return undefined.
Example:
Input: obj = { a: { b: { c: 42 } } }, path = "a.b.c"
Output: 42
Examples:
Input 1:
{"obj":{"a":{"b":{"c":42}}},"path":"a.b.c"}Output 1:
42Input 2:
{"obj":{"x":10},"path":"x"}Output 2:
10Loading editor...
Run your code to see results
Click the Run button above