Imagine we have a JSON stored in a variable named response
:
{
"brands": {
"Honda": [
"Accord",
"Civic"
],
"Porsche": [
"Cayenne",
"Cayman"
]
}
}
We want to retrieve the models within each brand. For instance:
for ( var car_brands in response.brands ) {
console.log(car_brands); // would print Honda, Porsche etc.
}
How can we iterate through car_brands
and also obtain the models (arrays) inside each one like Accord, Civic, etc. at the same time?
Perhaps a well-structured JSON format could simplify this parsing process.