JavaScript Intl.Collator for Multilingual Sorting, Search, and Filtering
UnicodeJavaScriptInternationalizationSearchSortingWeb Development

JavaScript Intl.Collator for Multilingual Sorting, Search, and Filtering

UUnicode Live Editorial Team
2026-11-17
6 min read

Use JavaScript Intl.Collator to sort and filter Unicode text across languages, with practical options, tests, and troubleshooting guidance.

JavaScript's default string order is not a reliable multilingual alphabet. This guide shows how to use Intl.Collator and String.prototype.localeCompare() to sort, compare, and filter Unicode text, with a reusable checklist for names, accented words, numbers, Turkish, German, Swedish, Arabic, and Japanese data.

Overview

Comparing strings with a < b or Array.prototype.sort() compares UTF-16 code units. That is useful for technical identifiers, but it does not represent the alphabetical rules people expect in different languages. Accented letters, case, digits, kana, and script-specific ordering can all produce surprising results.

Intl.Collator provides locale-aware comparison. Create a collator for the language and behavior your interface needs, then pass its comparison function to sort() or call it directly for equality and ordering checks.

const collator = new Intl.Collator("de", {
  sensitivity: "base",
  numeric: true
});

const names = ["Änne", "Anna", "Özil", "Zara"];
names.sort(collator.compare);

const sameForSearch = collator.compare("café", "CAFE") === 0;

The comparison result is negative, zero, or positive. Do not depend on a particular number such as -1 or 1; only its sign is part of the useful contract.

localeCompare() or Intl.Collator?

Both use the same internationalization machinery in modern JavaScript environments, but they suit different workflows.

NeedlocaleCompare()Intl.Collator
One comparisonConcise and convenientMore setup than necessary
Sorting many valuesWorks, but options are repeated if called inlineCreate once and reuse collator.compare
Shared search and sort rulesCan express the rules per callCentralizes locale and options
OptionsPass locale and options to each callConfigure once at construction
Inspecting behaviorLimited to the comparison callUse resolvedOptions() and supportedLocalesOf()

For example, a one-off comparison can be written as "ångström".localeCompare("zebra", "sv"). For a list, prefer const collator = new Intl.Collator("sv"); items.sort(collator.compare);. Reusing one configured collator also makes it less likely that sorting and filtering silently use different rules.

Important options

OptionUseful valuesWhat it controls
usagesort, searchWhether the comparison is intended for ordering or matching. Use the value that describes the interface behavior.
sensitivitybase, accent, case, variantHow differences in base letters, accents, and case affect comparison.
numerictrue, falseWhether digit sequences are compared numerically, so values such as item2 can come before item10.
caseFirstupper, lower, falseWhether uppercase or lowercase should be preferred when case is significant. The locale can influence the default.
ignorePunctuationtrue, falseWhether punctuation should have less influence on comparison. Validate this carefully for identifiers and codes.

Option support and defaults are locale-sensitive. Treat the requested configuration as a rule to test, not as a guarantee that every language orders every character in the same way.

Checklist by scenario

1. Sorting names and accented words

  1. Choose the locale from the user's language or the data's established editorial convention.
  2. Decide whether accents and case should distinguish entries.
  3. Create one collator and use it for the complete sort.
  4. Test names that differ only by case, accent, or a language-specific letter.
const nameCollator = new Intl.Collator("fr", {
  usage: "sort",
  sensitivity: "base"
});

const people = ["Émile", "emile", "Zoë", "Zoe"];
people.sort(nameCollator.compare);

sensitivity: "base" is often appropriate for a forgiving directory, but it can make distinct records compare as equal. Do not use a zero comparison as a database identity test unless that equivalence is explicitly intended.

2. Sorting values with numbers

Use numeric: true when digit sequences represent quantities or versions in a human-facing list.

const fileCollator = new Intl.Collator("en", { numeric: true });
["chapter10", "chapter2", "chapter1"].sort(fileCollator.compare);

Test leading zeros, decimal-looking strings, negative signs, and mixed letters before applying this to filenames or product codes. If the values are machine identifiers with a strict format, an explicit parser may be more predictable than locale-aware comparison.

For exact or whole-value matching, compare with a collator rather than lowercasing both strings. This avoids assuming that lowercase conversion is a complete model of language-aware equality.

const searchCollator = new Intl.Collator("tr", {
  usage: "search",
  sensitivity: "base"
});

const matches = searchCollator.compare("İstanbul", "istanbul") === 0;

Substring search is a separate problem. Intl.Collator compares complete strings; it does not return a match index or automatically find a locale-aware substring inside a longer string. For an autocomplete interface, combine a deliberate search strategy with tested normalization and locale rules, then use the collator for candidate comparison where appropriate.

4. Testing language-specific behavior

  • Turkish: Include dotted and dotless I, such as İ, i, I, and ı. Test with tr rather than assuming English case behavior.
  • German: Test ä, ö, ü, and ß against the ordering expected by your product or editorial rules. German collation conventions can differ from a simple character-code order.
  • Swedish: Include å, ä, and ö. Do not infer Swedish ordering from English or German results; test with sv.
  • Arabic: Use real Arabic words and review the displayed order in an RTL interface. Sorting order and visual direction are related to the product experience but are not the same operation.
  • Japanese: Test kanji, hiragana, katakana, and names with the locale and collation behavior your application expects. A displayed reading may be required when users need a specific gojūon-style directory order.

What to double-check

  1. Locale selection: Confirm whether the locale comes from the user, tenant, document, or a fixed business rule. A browser's default locale may not match the language of the dataset.
  2. Fallback behavior: Check which locale is actually used. Intl.Collator.supportedLocalesOf(["tr", "de", "sv", "ar", "ja"]) can help identify supported requests, while collator.resolvedOptions() exposes resolved settings.
  3. Normalization: Text can contain canonically equivalent sequences represented with different code points. Establish a consistent input policy and test composed and decomposed accented text. See the guide to Unicode normalization before using normalization in identifiers or search keys.
  4. Equality versus ordering: A comparison result of zero means “equivalent under these collator settings,” not necessarily “the same original string.” Preserve the original value and use a separate stable identifier.
  5. Rendering: Correct collation does not fix missing glyphs, fallback fonts, or bidirectional layout. For those issues, review CSS Unicode ranges and font fallback and bidirectional Unicode text.
  6. Runtime consistency: Browser and server runtimes may use different ICU or CLDR data. If sorted output is serialized, cached, or compared in tests, verify the environments together instead of assuming identical results.

Common mistakes

  • Using .sort() without a comparator: JavaScript then sorts values as strings by UTF-16 code units, which is rarely the desired multilingual order.
  • Calling toLowerCase() as universal search logic: Case conversion alone does not define locale-aware equality, especially for Turkish and other language-sensitive cases.
  • Creating a new collator inside a comparator: Configure it once outside the sort and reuse collator.compare.
  • Assuming one locale fits every user: “Alphabetical order” is a language and product decision, not a universal Unicode order.
  • Using numeric: true for every code: It can be wrong when digits are fixed-format identifiers rather than quantities.
  • Treating collation as transliteration: Sorting does not turn Arabic, Japanese, or accented text into Latin text. If you need slugs or search aliases, define that transformation separately; the Unicode-aware search and slug guide covers the distinction.
  • Ignoring grapheme boundaries: A visible character can contain multiple code points. Do not split user-visible text with naïve indexing when building advanced search or highlighting features.

When to revisit

Return to this checklist whenever you add a locale, change the language-selection model, introduce a new search field, or receive a report that alphabetical order differs between environments. It is also worth revisiting before seasonal planning cycles when catalogs, directories, or archived records are re-sorted in bulk.

Use this practical review sequence:

  1. Write down whether the operation is sorting, exact matching, autocomplete, or substring search.
  2. Choose representative fixtures for names, accents, numbers, case, and the scripts your users enter.
  3. Run the same fixtures in supported browsers and server runtimes.
  4. Record the locale, options, normalization policy, and expected order in tests.
  5. Check resolvedOptions() after runtime or dependency changes.
  6. Review the result with native-language stakeholders when the order affects a directory, ranking, or public-facing catalog.

For related Unicode debugging, see the guides to character escapes, Unicode property escapes, and multilingual line breaking. The central rule remains simple: make locale, comparison purpose, and equivalence rules explicit, then test them with the actual text your application handles.

Related Topics

#Unicode#JavaScript#Internationalization#Search#Sorting#Web Development
U

Unicode Live Editorial Team

Technical Editor

Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.