I'm trying to sort a list of strings with accented characters eg ["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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.