I have an API that is returning data in the following format:
[
{
"id": 12,
"acf": {
"address": {
"city": "Bandar Penawar",
"state": "Johor",
"country": "Malaysia",
}
},
{
"id": 16,
"acf": {
"address": {
"city": "Some City",
"state": "Arizona",
"country": "United States",
}
}
]
Right now, I'm getting the list of countries and states with the following computed code:
computed: {
countries() {
const countries = new Set();
this.$store.state.posts.forEach((post) =>
countries.add(post.acf.address.country)
);
return Array.from(countries);
},
states() {
const states = new Set();
this.$store.state.posts.forEach((post) =>
states.add(post.acf.address.state)
);
return Array.from(states);
},
},
This returns two separate arrays, countries and states, how can I organize the array by country, then states within that country?