+ 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
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);
})
+ 3
is it a question?
0
Frogged sorry if it was unclear, I've just rephrased the question