خرید بک لینک

Vote count: 0

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)?

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: جمعه 10 ارديبهشت 1395 ساعت: 9:19

صفحه بندی