flattenObject
接收一个对象obj
,深度优先遍历嵌套对象的可枚举属性,返回扁平化后的新对象,key 为字段路径字符串,value 为对应的值。
Added in v0.0.4
Usage
ts
import { flattenObject } from 'parsnip-kit'
const input0 = {
a: [1, 2, { b: 3 }],
c: {
d: [4, 5, { e: 6 }]
}
}
flattenObject(input0)
// {
// 'a[0]': 1,
// 'a[1]': 2,
// 'a[2].b': 3,
// 'c.d[0]': 4,
// 'c.d[1]': 5,
// 'c.d[2].e': 6
// }
const input1 = {
a: {},
b: [],
c: {
d: {},
e: []
}
}
flattenObject(input1) // {}
API
Type Parameter
Arg | Type | Description |
---|---|---|
T | extends object | 被扁平化对象的类型 |
Arguments
Arg | Type | Optional | Default | Description |
---|---|---|---|---|
obj | T | false | undefined | 扁平化的对象 |
Returns
Type |
---|
FlattenNestObject<T> |