【发布时间】:2022-01-10 01:44:24
【问题描述】:
有没有办法从条目中生成嵌套的 JavaScript Object?
Object.fromEntries() 并没有完全做到这一点,因为它不做嵌套对象。
const entries = [['a.b', 'c'], ['a.d', 'e']]
// Object.fromEntries(entries) returns:
{
'a.b': 'c',
'a.d': 'e',
}
// whatIAmLookingFor(entries) returns:
{
a: {
b: 'c',
d: 'e',
}
}
【问题讨论】:
标签: javascript json object serialization deserialization