How To Sort Special Letters (typescript)?
I want to sort some letters in ts... sort method and localCompare() sort in this way Ä, Å, Ö, instead of Å, Ä, Ö. How to sort any letters corectly? I have a list of objects:
Solution 1:
localeCompare
obviously depends on the locale, and different locales use different rules ("collations") to compare extended characters. For example, in English, A
s with different diacritics are all the same, while Swedish treats them differently:
console.log(["Älex2", "Ålex0", "Ålex3", "Alex1"].sort(( a, b ) => a.localeCompare(b, 'en')));
console.log(["Älex2", "Ålex0", "Ålex3", "Alex1"].sort(( a, b ) => a.localeCompare(b, 'sv')));
Post a Comment for "How To Sort Special Letters (typescript)?"