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

Signature TypeScript complète, extraite du fichier util.

typescript

API

Paramètres

Paramètres d'entrée acceptés par cet util.

obj
requis
any
The root object or array to traverse.
path
requis
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

Valeur de retour

La valeur retournée par cet util.

The value at the end of the path, or the fallback if the path cannot be resolved.

Usage

Exemples

Extraits de code prêts à coller.

Read a deeply nested property safely

typescript