【发布时间】:2022-07-09 00:35:39
【问题描述】:
[[{ id: 26, type: "Source", name: "Email" }], [{ id: 27, type: "Source", name: "Id" }, { id: 29, type: "Divider", name: "+" }, { id: 30, type: "Source", name: "SupplierId" }], [{ id: 28, type: "Source", name: "CommunityId" }]
如何将上面的对象数组转换为这样的数组数组,其中“名称”被挑出?
[["Email"],["Id","+", "SupplierId"],["CommunityId"]]
我已经尝试过像这样映射它:
this.exportColumns = columns.flatMap(obj => obj.sourceColumn).map(obj => obj?.name);
但我得到了这个结果:
[ "Email", "Id", "+", "SupplierId", "CommunityId" ]
【问题讨论】:
-
如果你不是
maps/flatMap/mergeMap的高手,你可以尝试先用普通的旧循环编写它,然后用RxJS操作符替换它们
标签: javascript arrays angular typescript object