I'm trying to sort a list of strings with accented characters e.g.["Zebra", "Apple", "Ähhhh"]
and I want it to look like ["Apple", "Ähhhh", "Zebra"]
Just running list.sort()
gives me ["Apple","Zebra","Ähhhh"]
Is there another built in function (like localeCompare
) that will let me sort this in the way I want it to be?
Thanks!
In general, yes, you can sort by different locale.
let ar = ["Apple","Zebra","Ähhhh"];
ar.sort((a,b) => a.localeCompare(b, 'en'))
However, as to the exact sorting you're looking for, you'll have to replace 'en' with the appropriate locale, if there is one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With