As the data for a simple online store is extracted from a headless CMS, it is structured in the following format:
[
{
"id": 12312,
"storeName": "Store1",
"googleMapsUrl": "https://example1.com",
"country": "Australia",
"state": "New South Wales"
},
{
"id": 12313,
"storeName": "Store2",
"googleMapsUrl": "https://example2.com",
"country": "Australia",
"state": "Queensland"
},
{
"id": 12314,
"storeName": "Store3",
"googleMapsUrl": "https://example3.com",
"country": "Indonesia",
"state": "Java"
},
]
This data will be utilized to create a user-friendly store locator that is categorized by Country followed by State.
No modifications can be made on the CMS system. Therefore, I am seeking recommendations on how to iterate through this flat data structure and arrange it according to country and state.
UPDATE: An attempt was made to isolate unique countries using the following code snippet:
let newArray = this.$page.stores.edges.map(item =>{
let newObj = {};
newObj[item.node.country] = item.node.country;
newObj[item.node.country.state] = item.node.state;
console.log(newObj)
return newObj;
});
However, it remains unclear on how to proceed further to link these countries with respective states and eventually the stores themselves.