If I need to retrieve a list of just the types
of cars from this dataset:
let vehicles = [
{
magnet: [
true
],
cars: [
{
type: "BMW"
}
],
name: "Roby"
},
{
magnet: [
false
],
cars: [
{
type: "Mercede"
}
],
name: "Max"
}
];
Is there a more optimal approach than iterating through the data once like this? I am concerned about assuming that there is only one item in the cars
array.
vehicles.map(car => {
return car.cars[0].type
})