Intl

Intl.Collator

Creates an Intl.Collator object that enables language-sensitive string comparison

Syntax

JavaScript
new Intl.Collator(locales?, options?)

Parameters

ParameterTypeDescription
localesstring | string[]A BCP 47 language tag or array of tags
optionsIntl.CollatorOptionsOptions: sensitivity, caseFirst, numeric, usage

Return Value

An Intl.Collator object with a compare() method

Examples

Basic Usage
const collator = new Intl.Collator('en')
const sorted = ['banana', 'apple', 'Cherry'].sort(collator.compare)
console.log(sorted) // ['apple', 'banana', 'Cherry']
Practical Example
const collator = new Intl.Collator('en', { sensitivity: 'base' })
console.log(collator.compare('a', 'A')) // 0 (equal)
console.log(collator.compare('a', 'b')) // negative
Advanced Usage
const collator = new Intl.Collator('en', { numeric: true })
const files = ['file10', 'file2', 'file1', 'file20']
console.log(files.sort(collator.compare))
// ['file1', 'file2', 'file10', 'file20']

Understanding Intl.Collator

The Intl.Collator method in JavaScript creates an Intl.Collator object that enables language-sensitive string comparison. It belongs to the Intl object and is one of the most widely used methods for working with intl values in modern JavaScript and TypeScript applications.

The method signature is new Intl.Collator(locales?, options?). It accepts 2 parameters: locales, options. When called, it returns an intl.collator object with a compare() method. Understanding when and how to use Collator() helps you write more expressive, readable code.

Common use cases for Intl.Collator include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like intl-collator-compare, intl-segmenter, intl-numberformat, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for Intl.Collator is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.

Browser Compatibility

Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.

Related Methods

More Intl Methods

Other methods in the Intl object

Related Tools

More Intl Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.