Before you may vote me down: I have checked all existing solutions around this problem but none was similar to this.
I want to sort this array alphabetically by image.name (JavaScript or jQuery):
var myArray = [{
creator: {
"firstname": "Sally",
familyname: "Bloomfield"
},
location: {
"lat": 12.123,
lng: 8.846
},
image: {
name: "Hello World",
size: "50x80"
}
},
{
creator: {
firstname: "Bob",
familyname: "Jones"
},
location: {
lat: 31.593,
lng: 96.376
},
image: {
name: "Flowerpower",
size: "40x50"
}
},
{
creator: {
firstname: "John",
familyname: "Walker"
},
location: {
lat: 27.184,
lng: 123.120
},
image: {
name: "Guiness",
size: "33x66"
}
}
];
The array output after sort:
[{
creator: {
firstname: "Bob",
familyname: "Jones"
},
location: {
lat: 31.593,
lng: 96.376
},
image: {
name: "Flowerpower",
size: "40x50"
}
},
{
creator: {
firstname: "John",
familyname: "Walker"
},
location: {
lat: 27.184,
lng: 123.120
},
image: {
name: "Guiness",
size: "33x66"
}
},
{
creator: {
firstname: "Sally",
familyname: "Bloomfield"
},
location: {
lat: 12.123,
lng: 8.846
},
image: {
name: "Hello World",
size: "50x80"
}
}
]
So first image Flowerpower then Guiness then Hello World.
The existing sort function of Javascript can't handle this as I have tried that out. Is it even possible to sort such structures?
Any help is appreciated.