getNestedValue
Commons
stable
Safely drills into a nested object following an array path of string/number keys and returns the value found, or a fallback when any segment is null or the key is absent.
API
Signature
Full TypeScript signature sourced from the util file.
API
Parameters
Input parameters accepted by this util.
- objrequiredany
- The root object or array to traverse.
- pathrequiredArray<(string | number)>
- An array of property keys (strings) or array indices (numbers) describing the access path from the root.
- fallbackany
- Value returned when any segment in the path is null, or the final key is absent. Defaults to undefined.
API
Return value
The value returned by this util.
- The value at the end of the path, or the fallback if the path cannot be resolved.
Usage
Examples
Ready-to-paste usage snippets.
Read a deeply nested property safely