【发布时间】:2022-01-02 14:56:12
【问题描述】:
如何将嵌套的对象数组转换为具有特定键名的非嵌套对象:
data = [{department: 'IT', total: 7, planned: 5,
units: [
{name: 'HR', total: 30, planned: 5, description: 'HR Admin'},
{name: 'Sales', total: 4, planned: 9, description: 'Sales Admin'}
]
}]
我需要的输出应该是:
data = [
{name: 'IT', total: 7, planned: 5, description: ''},
{name: 'HR', total: 30, planned: 5, description: 'HR Admin'},
{name: 'Sales', total: 4, planned: 9, description: 'Sales Admin'}
]
【问题讨论】:
-
欢迎来到 Stack Overflow!访问help center,使用tour 了解内容和How to Ask。请首先>>>Search for related topics on SO,如果您遇到困难,请发布您的尝试的minimal reproducible example,并使用
[<>]记录输入和预期输出sn-p 编辑器。
标签: javascript arrays object ecmascript-6