I have a JSON that looks like this (the users are the root objects):
// resp.data
[
{ useame: '', building [ { buildingInfo: '' } ] },
{ useame: '', building [ { buildingInfo: '' } ] },
// etc ...
]
And I'm using this:
let buildings = []
if (userRole === 'admin') {
resp.data.forEach(user => {
if (user.building) {
user.building.forEach(building => {
buildings.push(buildingTemplate(building, user.useame))
})
console.log(buildings)
}
})
}
To tu it into this (the buildings are the root objects):
[
{ useame: '', buildingInfo: '' },
{ useame: '', buildingInfo: '' },
// etc ...
]
Is there a way to avoid those two nested forEach loops? (Maybe using a method provided by Lodash)?
