I have a JSON array of objects of the format
var employees =
[
{
"employee1": "employee1",
"Details": [
{
"title": "Software Engineer",
"EmployeeId": 451
}
]
},
{
"employee2": "employee2",
"Details": []
},
{
"employee3": "employee3",
"Details": [
{
"title": "Test analyst",
"EmployeeId": 453
}
]
},
{
"employee4": "employee4",
"Details": [
{
"title": "Software engineer",
"EmployeeId": 487
},
{
"title": "Architect",
"EmployeeId": 500
}
]
}
]
What's the best way to get the EmployeeIds?
Expected output:
[451,453,487,500]
When I used:
console.log(Object.assign({}, ...employees).Details.map(t=>t.EmployeeId))
It is returning the result as:
[487,500]
Is there a way to concatenate other employee Ids in the result?
employees.map(m => m.Details.map(m => m.EmployeeId)).flat()employees.flatMap(m => m.Details.map(m => m.EmployeeId)):pflatMapwould be better, I kind of kept it at 2 map's to hopefully point the OP in the direction why his failed.