Home

IntlCollator

Intl.Collator is a constructor in the ECMAScript Internationalization API that creates objects capable of comparing strings according to locale- and language-specific rules. It encapsulates locale data and options so that sorting and searching can be performed in a way that respects linguistic conventions for the selected language or region. Implementations rely on Unicode CLDR data and are available in modern web browsers and Node.js.

An Intl.Collator object provides a compare(a, b) function. The function returns a negative number if a comes

Locales and options. You create a collator with new Intl.Collator(locales, options). Locales can be a string

Example usage. const coll = new Intl.Collator('fr-FR', { numeric: true, sensitivity: 'base' }); const arr = ['2','10','1']; arr.sort(coll.compare) sorts numerically

---

before
b,
zero
if
they
are
considered
equivalent,
or
a
positive
number
if
a
comes
after
b,
according
to
the
configured
locale
and
options.
The
same
compare
function
can
be
used
as
a
comparator
when
sorting
arrays.
The
constructor
also
exposes
supportedLocalesOf(locales)
to
query
which
locales
are
available,
and
resolvedOptions()
to
inspect
the
actual
locale
and
option
values
being
used.
or
an
array
of
strings.
Options
include
localeMatcher
('lookup'
or
'best
fit'),
usage
('sort'
or
'search'),
numeric
(true
to
compare
numbers
numerically),
caseFirst
('upper',
'lower',
or
'false'),
sensitivity
('base',
'accent',
'case',
or
'variant'),
ignorePunctuation
(true
or
false),
and
collator-specific
rules
such
as
collation.
Not
all
options
are
supported
by
every
environment.
according
to
French
conventions.
Locale
data
and
option
support
may
vary
by
engine,
so
resolvedOptions()
can
help
confirm
exact
behavior.