Currently, I am working with some JSON data that has the following structure:
const data = {
"stores": [
{
"name": "s1",
"id": "6fbyYnnqUwAEqMmci0cowU",
"customers": [
{
"id": "4IhkvkCG9WWOykOG0SESWy",
"name": "customer2",
},
{
"id": "4IhkfikCG9WWOykOG0SESWy",
"name": "customer1",
},
{
"id": "9IfkvkCG9WWOykOG0SESWy",
"name": "customer100",
},
]
},
{
"name": "s2",
"id": "2D1fTgjAJ20ImiAqsWAEEI",
"customers": [
{
"id": "3dfkvkCG9WWOykOG0SESWy",
"name": "customer9",
},
]
},
{
"name": "s3",
"id": "6rxmPFzIHKQ0EOAGGkAwKg",
"customers": [
{
"id": "7IfkvkCG9WWOykOG0SESWy",
"name": "customer7",
},
]
}
]
}
My task is to organize this data by sorting the customers' names. Here's what I have tried so far:
const sortedData = data.stores.sort(function(c1, c2) {
return c1.customers[0].name < c1.customers[0].name;
}).map(storeInfo => (
// Need to do something else with sorted data
)
However, my current method doesn't seem to be effective because it doesn't handle nested levels properly. Any assistance on this matter would be greatly appreciated.
Desired Outcome: Arrange the list of customers in alphabetical order within each store and then sort them among all the stores as well.