Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sorting Accented Characters

Tags:

javascript

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!

like image 460
Tim Avatar asked Oct 19 '25 08:10

Tim


1 Answers

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.

like image 129
pwilcox Avatar answered Oct 22 '25 05:10

pwilcox



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!