Home JavaScript Intl Methods Intl.Collator() JavaScript Intl.Collator() Constructor Definition new Intl.Collator(locales, options) builds an object that compares strings the way a language expects. Call compare(a, b) to get a negative number, zero or a positive number, just like a sort compare function.
Options such as numeric: true make "2" sort before "10", and sensitivity controls whether case or accents count as different.
new Intl.Collator(locales, options)
collator.compare(a, b)
compare → negative | 0 | positive
numeric: true → "2" before "10"
sensitivity: "base" → ignore case/accents Syntax Create a collator, then pass compare to Array.prototype.sort.
const names = ["Zoe", "anne", "Bob"];
names.sort(new Intl.Collator("en").compare);
console.log(names.join(", ")); Call What it does new Intl.Collator("en")English string compare rules. collator.compare("a", "b")Negative if a comes first, 0 if equal, positive if a comes later. new Intl.Collator("en", { numeric: true })Compare digit runs as numbers. new Intl.Collator("en", { sensitivity: "base" })Treat "A" and "a" as the same.
A standard JavaScript constructor on the Intl object: create one with new Intl.Collator(). No import required. Siblings: Intl.getCanonicalLocales() , Intl.supportedValuesOf() , Intl.DateTimeFormat() , Intl.DisplayNames() , Intl.DurationFormat() , Intl.ListFormat() , Intl.Locale() , Intl.NumberFormat() , Intl.PluralRules() , Intl.RelativeTimeFormat() , Intl.Segmenter() .
Library declarations // ECMAScript 2015 — Intl.Collator
new Intl.Collator(locales, options)
collator.compare(string1, string2)
// options.numeric : boolean
// options.sensitivity : "base" | "accent" | "case" | "variant"
// compare returns : negative | 0 | positive Parameters Parameter Description locales Optional. A locale string or list, such as "en" or "de-DE". options Optional. Object with flags such as numeric and sensitivity. string1, string2 For compare: the two strings to compare.
Return Value Return Value Description Collator object new Intl.Collator() returns a collator with a compare method.number compare returns negative, zero or positive for sort order.
JavaScript Examples 1. Sort names 2. Numeric option 3. Sensitivity Example 1 — Sort Names with Locale Rules Sort a small list of names with an English collator.
const names = ["Zoe", "anne", "Bob"];
const sorted = [...names].sort(new Intl.Collator("en").compare);
console.log("Sorted: " + sorted.join(", ")); How It Works Copy first. Spread into a new array so the original list stays unchanged.Locale sort. English rules put anne before Bob before Zoe.Ready for UI. Use the same pattern for any name list in one language.Example 2 — Sort "2" Before "10" with numeric Without numeric, string sort puts "10" before "2". Turn the option on to fix that.
console.log("Plain: " + ["10", "2", "1"].sort(new Intl.Collator("en").compare).join(", "));
console.log("Numeric: " + ["10", "2", "1"].sort(new Intl.Collator("en", { numeric: true }).compare).join(", ")); Plain: 1, 10, 2
Numeric: 1, 2, 10 How It Works Default is text. Digit characters are compared as text, so "10" starts with "1" and can sort before "2".numeric: true. Digit runs are compared as numbers, so 2 comes before 10.Useful for versions. File names like ch2 and ch10 sort naturally.Example 3 — Ignore Case with sensitivity base With sensitivity: "base", upper and lower case letters compare as equal.
const base = new Intl.Collator("en", { sensitivity: "base" });
const full = new Intl.Collator("en");
console.log("Base A vs a: " + base.compare("A", "a"));
console.log("Full A vs a: " + full.compare("A", "a"));
console.log("Base a vs b: " + base.compare("a", "b")); Base A vs a: 0
Full A vs a: 1
Base a vs b: -1 How It Works Base ignores case. compare("A", "a") returns 0.Default keeps case. A full compare still sees a difference between A and a.Different letters differ. Even with base sensitivity, a still sorts before b.Compatibility
Browser & Runtime Support Intl.Collator is part of the original ES2015 Intl API (or arrived soon after and is now everywhere). Every current browser and Node.js has it.
✓ ES2015 · Widely supported
Intl.Collator Supported in Chrome 24+, Edge 12+, Firefox 29+, Safari 10+, Opera 15+ and Node.js 0.12+. Internet Explorer had partial Intl support only.
Google Chrome 24+ · Desktop & Mobile
Full support
Microsoft Edge 12+ · Chromium based
Full support
Mozilla Firefox 29+ · Desktop & Mobile
Full support
Apple Safari 10+ · macOS & iOS
Full support
Opera 15+ · Chromium based
Full support
Samsung Internet Recent versions · Android
Supported
Android WebView 24+ · Chromium based
Supported
Node.js 0.12+ · Server runtime
Supported
Deno Supported · JavaScript runtime
Supported
Bun Supported · JavaScript runtime
Supported
Internet Explorer No native support
Not supported Intl.Collator Excellent
Bottom line: Safe to use in every current browser and in Node.js. No feature-detect needed for modern code.
Frequently Asked Questions What does Intl.Collator do? It compares strings using the rules of a language, so you can sort names and labels the way readers expect.
How do I use Collator with Array sort? Create a collator and pass collator.compare as the compare function: array.sort(new Intl.Collator("en").compare).
What does numeric: true change? It compares groups of digits as numbers, so "2" sorts before "10" instead of after.
What is sensitivity? It controls which differences count. "base" ignores case and accents; "variant" treats almost every difference as meaningful.
Do I need a new Collator for every compare? No. Create one collator and reuse its compare method for many pairs or many sorts.
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
13 people found this page helpful
Helpful Share Copy link Suggestion