On this page
  1. Intl.Collator
  2. Signature & Overview
  3. Notes & Pitfalls
  4. Example

Intl.Collator

Prev: DateTimeFormat | Up: Intl | Next: Global
Rel: Intl, String, RegExp & Intl Guide
Ref: MDN Web Docs — Intl.Collator
Tags: #public #web #javascript #builtins #intl #tier/standard


Signature & Overview

new Intl.Collator(locales?, options?)

Locale-aware string comparison (including natural numeric sorting with { numeric: true }).

Notes & Pitfalls

Example

const collator = new Intl.Collator("en", { numeric: true, sensitivity: "base" });
const files = ["img10.png", "img2.png", "img1.png"].toSorted(collator.compare);
console.assert(JSON.stringify(files) === '["img1.png","img2.png","img10.png"]');

Linked from

Related notes