getObjectValueByPath

Commons
stable

Resolves a dot-notation (or bracket-notation) path string against an object and returns the found value, or a fallback when null or 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 to traverse. Returns fallback immediately when null or undefined.
path
string | null
A dot-separated property path (e.g. "user.profile.name") or bracket notation (e.g. "items[0].value"). Leading dots and bracket indices are normalised automatically.
fallback
any
Value returned when the path cannot be resolved. Defaults to undefined.

API

Valeur de retour

La valeur retournée par cet util.

The value found at the specified path, or the fallback.

Usage

Exemples

Extraits de code prêts à coller.

Dot-path and bracket-path traversal

typescript