I'm trying to work out how to group data at two levels using for loops in VueJS
As an example I have a VueJS app with the following data:
cars: [{
"make": "Ford",
"model": "Mustang"
}, {
"make": "Ford",
"model": "Thunderbird"
}, {
"make": "Ford",
"model": "Fairlane"
}, {
"make": "Chevrolet",
"model": "Camaro"
}, {
"make": "Chevrolet",
"model": "Chevelle"
}, {
"make": "Plymouth",
"model": "Barracuda"
}]
It's straightforward to loop through the cars using a for loop:
<div v-for="car in cars">
<div>Make: {{ car.make }}</div>
<div>Model: {{ car.model }}</div>
</div>
But what if I wanted to group the models by make? The output I'm after is:
Ford
Mustang
Thunderbird
Fairlane
Chevrolet
Camaro
Chevelle
Plymouth
Barracuda
What's the best way to do this in VueJS?