I am trying to loop through nested arrays using map.
const results = [
{
id: 1,
details: [
{
color: "red",
}
]
},
{
id: 2,
details: [
{
color: "blue",
}
]
}]
const list1 = results.map(car => {
return car.details;
})
const list2 = list.map(details => {
return {
detail: details.color
}
});
console.log(list1);
console.log(list2);
List1 is displaying fine:
[ [ { color: 'red' } ], [ { color: 'blue' } ] ]
However with list2 I am getting the following:
[ { detail: undefined }, { detail: undefined } ]
Could anyone help me to map through the nested array?
[ { detail: undefined }, { detail: undefined } ]?list?list1instead oflist.