Skip to main content

Get Value from Object by Path

MIDDLE

Get Value from Object by Path

Get a nested value from object using a path string.

Requirements:

  • Access nested object properties
  • Path is string with dot notation (e.g., "a.b.c")
  • Return undefined if path doesn't exist

Example:

const obj = { a: { b: { c: 42 } } };

Input: getNestedValue(obj, "a.b.c")
Output: 42

Input: getNestedValue(obj, "a.b.d")
Output: undefined

Examples:

Input 1:{"obj":{"a":{"b":{"c":42}}},"path":"a.b.c"}
Output 1:42
Input 2:{"obj":{"a":{"b":{"c":42}}},"path":"a.b.d"}
Output 2:

Loading editor...

Run your code to see results

Click the Run button above