I have a dictionary-style array object in JavaScript shown below and would like to sort it by a property. How would this be done? I know questions similar to this have been answered but I think my structure is different. Simply running array.sort(compare)
is not working for me because I don't have integers for indexes. Thanks!
var myData = {
"userOne": {
"firstName": "Felix",
},
"userTwo": {
"firstName": "Bob",
},
"userThree": {
"firstName": "Anna",
}
}
I would like the above array myData
to be sorted by firstName
so that the object with Anna
appears first, followed by Bob
, followed by Felix
. Thank you so much!!