+ 3

Sort an array of objects

Can someone help me sort an array of object using map method, and/or any other optimal means, based on the code below. I used sort for it, but I'm thinking it may not be the most efficient way of doing it. I sorted by using the objects age key. How do I sort by a key whose value is a string? https://code.sololearn.com/W8dvoVTY9NnR/?ref=app

11th Jan 2021, 11:41 AM
Nyakotey🇬🇭🎹
Nyakotey🇬🇭🎹 - avatar
3 Antworten
+ 8
I did something by sorting them by alphabetical order..but I didn't understand whether I have to sort it by it's name or age.. person.sort(function(a,b){ return a.name.localeCompare(b.name); })
11th Jan 2021, 4:02 PM
Aditya
Aditya - avatar
+ 3
is it a question?
11th Jan 2021, 2:07 PM
Oma Falk
Oma Falk - avatar
0
Frogged sorry if it was unclear, I've just rephrased the question
11th Jan 2021, 5:12 PM
Nyakotey🇬🇭🎹
Nyakotey🇬🇭🎹 - avatar