[[{ 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" }]
如何将上面的 object 数组转换为 arrays 数组,像这样,其中“名称”被挑出?
[["Email"],["Id","+", "SupplierId"],["CommunityId"]]
我已经尝试像这样 map 它:
this.exportColumns = columns.flatMap(obj => obj.sourceColumn).map(obj => obj?.name);
但我得到了这个结果:
[ "Email", "Id", "+", "SupplierId", "CommunityId" ]
回答1
在 arrays 的第一层内使用第二个 map
data.map(item => item.map(i => i.name));