I have the following array that I need to sort by countries in alphabetical order:
data=[
{
"country": "China",
"brands": {
"abc": "123",
"def": "123",
},
"day": "2020-04-16",
"time": "2020-04-16T14:30:05+00:00"
},
{
"country": "Zimbawe",
"brands": {
"abc": "123",
"def": "123",
},
"day": "2020-04-16",
"time": "2020-04-16T14:30:05+00:00"
},
{
"country": "Africa",
"brands": {
"abc": "123",
"def": "123",
},
"day": "2020-04-16",
"time": "2020-04-16T14:30:05+00:00"
}
]
I've tried this, so far:
data.sort()
and also this:
function(a, b){return a - b}
but it still returns the same order as the original array. So how do I sort this using country as the basis?