CKTIS / JavaScript
Intl.Collator — comparing text using language rules
Intl.Collator compares strings using the rules of a selected locale. Its compare function can be passed directly to sorting; the sign of the result matters, not a particular numeric value.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
const collator = new Intl.Collator(locales, options);
collator.compare(a, b);
array.sort(collator.compare);Intl.Collator belongs to the ECMA-402 internationalization standard, not the DOM interfaces. It creates an object that compares text according to locale settings (locales) and options (options). Specifying a locale explicitly reduces dependence on the environment's defaults.
Intl.Collator.prototype.compare is an accessor returning a function bound to the instance. You can pass collator.compare directly to array.sort(...), without bind. A negative result means the first string precedes the second, a positive result means it follows, and 0 means equivalence under the comparison rules. Do not assume exactly -1 or 1; 0 need not mean identical strings.
usage: "sort" is for ordering, whereas usage: "search" is for testing equivalence, not sorting. sensitivity controls which differences matter: "base", "accent", "case", or "variant". numeric: true enables comparing digit sequences as numbers when supported by the environment.
Locale data and ordering details depend on the implementation. Check API availability and required locales in the target browser; availability in Node 24 does not establish browser support. Intl.Collator.supportedLocalesOf(...) helps check locales, while collator.resolvedOptions() exposes the settings actually selected.
Examples
const collator = new Intl.Collator("en", { usage: "sort" });
const words = ["c", "a", "b"];
console.log(words.sort(collator.compare).join(","));
console.log(collator.compare("a", "b") < 0);
console.log(collator.compare("a", "a") === 0);Result
a,b,c true true
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.