JavaScript Intl.Collator() Constructor

Beginner
6 min read
Updated: Nov 2026
3 examples
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.

Remember
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.

JavaScript
const names = ["Zoe", "anne", "Bob"];
names.sort(new Intl.Collator("en").compare);
console.log(names.join(", "));
CallWhat 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
JavaScript
// 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

ParameterDescription
localesOptional. A locale string or list, such as "en" or "de-DE".
optionsOptional. Object with flags such as numeric and sensitivity.
string1, string2For compare: the two strings to compare.

Return Value

Return ValueDescription
Collator objectnew Intl.Collator() returns a collator with a compare method.
numbercompare returns negative, zero or positive for sort order.

JavaScript Examples

Example 1 — Sort Names with Locale Rules

Sort a small list of names with an English collator.

JavaScript
const names = ["Zoe", "anne", "Bob"];
const sorted = [...names].sort(new Intl.Collator("en").compare);

console.log("Sorted: " + sorted.join(", "));
Try It Yourself

How It Works

  1. Copy first. Spread into a new array so the original list stays unchanged.
  2. Locale sort. English rules put anne before Bob before Zoe.
  3. 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.

JavaScript
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(", "));
Try It Yourself

How It Works

  1. Default is text. Digit characters are compared as text, so "10" starts with "1" and can sort before "2".
  2. numeric: true. Digit runs are compared as numbers, so 2 comes before 10.
  3. 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.

JavaScript
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"));
Try It Yourself

How It Works

  1. Base ignores case. compare("A", "a") returns 0.
  2. Default keeps case. A full compare still sees a difference between A and a.
  3. Different letters differ. Even with base sensitivity, a still sorts before b.

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.

ES2015 Standard since
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

It compares strings using the rules of a language, so you can sort names and labels the way readers expect.
Create a collator and pass collator.compare as the compare function: array.sort(new Intl.Collator("en").compare).
It compares groups of digits as numbers, so "2" sorts before "10" instead of after.
It controls which differences count. "base" ignores case and accents; "variant" treats almost every difference as meaningful.
No. Create one collator and reuse its compare method for many pairs or many sorts.

Next: Intl.DateTimeFormat

Learn how to format dates and times with locales and time zones.

Intl.DateTimeFormat tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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