getPath
function getPath<T>(
source: unknown,
path: string | Array<string | number>,
fallback?: T
): T | undefined;
The path is either a dotted string or an array of segments; array indices go in as numbers, as in ["rows", 0, "id"]. Bracket syntax inside a string is not parsed — "rows[0].id" finds nothing.
A missing or nil link anywhere along the path yields the fallback instead of throwing, which is the whole point over a.b.c.
Parameters
Parameter | Type | Description |
|---|---|---|
|
| The value to read from. |
|
| A dotted string, or an array of keys and indices. |
|
| Returned when the path does not resolve. |
Returns
T | undefined — the value at the path, or the fallback.
Examples
Reading
getPath({ a: { b: 1 } }, "a.b"); // => 1
getPath({}, "a.b", "fallback"); // => "fallback"
getPath({ rows: [{ id: 7 }] }, ["rows", 0, "id"]); // => 7
See also
Source
23 September 2026
This documentation was generated with AI (Claude) from the library's source code.