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 |
|---|---|---|
|
| The object to flatten. It must not be an array. |
|
| 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 |
|---|---|
| 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
23 September 2026
This documentation was generated with AI (Claude) from the library's source code.