I am trying to sort alphabetically array of objects based on their usernames. Basically array of users is something like this
users = [
{
firstName: 'Ana'
lastName: 'Smith'
username: 'Ana'
id: 1
email: 'ana@ana.com'
},
{
firstName: 'Ana'
lastName: 'AnaWithSpecialA'
username: 'Äna'
id:2
email: 'ana2@ana.com'
},
{
firstName: 'Bla'
lastName: 'Blabla'
username: 'Bla'
id:3
email:'bla@bla.com'
}
]
I use this function for sorting:
users.sort((a, b) => {
if(a.username < b.username) return -1;
if(a.username > b.username) return 1;
return 0
});
But users with usernames that start with Ä, Ö, Ü always end up last. This is German alphabet letters btw. How can I push them so that Ä can be behind A and Ö behind O etc, or whatever is the correct way of sorting?