apps-script-utils 2.1.1 Help

flat

function flat(source: object, depth: number = Infinity): Record<string, unknown>;

Nested objects become dotted paths; arrays are kept whole, because their indices are data rather than structure. depth stops the descent — 1 flattens the first level only.

The inverse walk is getPath, which reads a value back out by the same kind of path.

Parameters

Parameter

Type

Description

source

object

The object to flatten. It must not be an array.

depth (optional) = Infinity

number

How many levels to descend. Any whole number; unlimited by default.

Returns

Record<string, unknown> — a new flat object keyed by dotted paths.

Throws

Exception

Condition

IllegalArgumentException

the value is not an object.

Examples

Flattening

flat({ a: { b: 1 }, c: [1, 2] }); // => { "a.b": 1, "c": [1, 2] } flat({ a: { b: { c: 1 } } }, 1); // => { "a.b": { "c": 1 } }

See also

Source

src/lang/object/flat.ts

23 September 2026

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