JavaScript Intl.Collator Object
Intl.Collator compares strings in a language-aware way, for sorting names and words correctly, including accents and numbers within text.
Description
Intl.Collator creates an object for language-sensitive string comparison. Its compare function returns a negative, zero or positive number and can be passed straight to Array.prototype.sort(). Unlike the default sort, it places accented letters next to their base letters and follows each language's alphabet.
Options include numeric: true to sort "item 10" after "item 2", and sensitivity: 'base' to treat "a", "A" and "á" as equal. For sorting many strings it is faster than calling localeCompare() each time.
The usage option can be set to 'search' for matching rather than sorting, and the caseFirst option decides whether upper or lower case sorts first. Some languages have several sort orders, such as German phonebook order, which you can request with a locale extension like 'de-u-co-phonebk'. Collation is what makes sorted lists of names feel natural to speakers of each language.
Creating
new Intl.Collator(locales, options)Example
Browser Support
The following information will show you the current browser support for the Intl.Collator object. Hover over a browser icon to see the version that first introduced support for this object.
Desktop





Tablets & Mobile





