I am facing the challenge of parsing through an array of objects that contain embedded arrays of objects. My goal is to use .filter() to achieve this, but I need to verify if the embedded array includes at least one of several specified object types. Allow me to illustrate using an example:
Imagine an array of Garage objects with a "cars" field, which consists of an array of cars. Each car is represented as an object with an array of qualities. I want to identify the garages that have at least one "fast" car and at least one "tiny" car. It's acceptable for a single car to possess both qualities. How can I efficiently accomplish this task in JavaScript?
garageArray = [
{
id: 10,
cars: [
{id: 1, qualities: ["fast", "small"]},
{id: 2, qualities: ["offRoad", "large"]},
{id: 3, qualities: ["fast", "loud"]}
]
},
{
id: 20,
cars: [
{id: 4, qualities: ["loud"]},
{id: 5, qualities: ["fast", "tiny"]}
]
},
{
id: 30,
cars: [
{id: 6, qualities: ["slow", "small"]},
{id: 7, qualities: ["offRoad", "tiny"]},
{id: 8, qualities: ["fast", "loud"]}
]
}
]
The desired outcome should consist of Garages with the ids of 20 and 30.