apps-script-utils 2.1.1 Help

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

source

unknown

The value to read from.

path

string \| Array<string \| number>

A dotted string, or an array of keys and indices.

fallback (optional)

T

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

src/lang/object/getPath.ts

23 September 2026

This documentation was generated with AI (Claude) from the library's source code.