【发布时间】:2017-07-11 15:24:25
【问题描述】:
假设如下数组:
[
{id: 1234, name: "@Acme", sources:["Twitter"]},
{id: 5678, name: "@Enron", sources:["Facebook"]},
]
我想将sources[0] 提升为属性值,可以在源本身下,也可以使用lodash 作为新键。
我做了以下事情:
myList = _.map(monitorList, _.partialRight(_.pick, ['id', 'name', 'sources']));
mySources = _.map(monitorList, 'sources');
我想我现在可以遍历每个相应的数组并将我的索引从 mySources 映射到 myList 中的源键,但是似乎应该有一种使用 lodash 将嵌套数组项提升为属性值。
理想的最终数据结构:
[
{id: 1234, name: "@Acme", sources:"Twitter"},
{id: 5678, name: "@Enron", sources:"Facebook"},
]
【问题讨论】:
-
您能否也显示您想要实现的预期输出结构?
-
@guwere 更新了更多细节
标签: javascript ecmascript-6 lodash