mirror of
https://github.com/toss/es-toolkit.git
synced 2024-11-30 18:23:22 +03:00
43 lines
644 B
Markdown
43 lines
644 B
Markdown
# flattenObject
|
|
|
|
Flattens a nested object into a single-level object with dot-separated keys.
|
|
|
|
- `Array`s are flattened.
|
|
- Non-plain objects, like `Buffer`s or `TypedArray`s, are not flattened.
|
|
|
|
## Signature
|
|
|
|
```typescript
|
|
function flattenObject(object: object): Record<string, any>;
|
|
```
|
|
|
|
### Parameters
|
|
|
|
- `object` (`object`): The object to flatten.
|
|
|
|
### Returns
|
|
|
|
(`T`): The flattened object.
|
|
|
|
## Examples
|
|
|
|
```typescript
|
|
const nestedObject = {
|
|
a: {
|
|
b: {
|
|
c: 1,
|
|
},
|
|
},
|
|
d: [2, 3],
|
|
};
|
|
|
|
const flattened = flattenObject(nestedObject);
|
|
console.log(flattened);
|
|
// Output:
|
|
// {
|
|
// 'a.b.c': 1,
|
|
// 'd.0': 2,
|
|
// 'd.1': 3
|
|
// }
|
|
```
|