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.

typescript

API

Parameters

Input parameters accepted by this util.

obj
required
any
The root object or array to traverse.
path
required
Array<(string | number)>
An array of property keys (strings) or array indices (numbers) describing the access path from the root.
fallback
any
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

typescript