I will like to print [4, 5, 2] as the value of supervisors in the following nested array/objects.
var data = {
supervisors: [
{
0: [
{
id: 4,
name: "Reporter"
}
]
},
{
1: [
{
id: 5,
name: "Officer"
}
]
},
{
2: [
{
id: 2,
name: "Coordinator"
}
]
},
]
};
How can I loop through the data?
Array.mapfor this. And you obviously need to know how to access properties and array elements.data.supervisors.flatMap(item => Object.values(item).map(value => value[0].id))