This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2021.
The of() method of Intl.DisplayNames instances receives a code and returns a string based on the locale and options provided when instantiating this Intl.DisplayNames object.
const regionNamesInEnglish = new Intl.DisplayNames(["en"], { type: "region" });
const regionNamesInTraditionalChinese = new Intl.DisplayNames(["zh-Hant"], {
type: "region",
});
console.log(regionNamesInEnglish.of("US"));
// Expected output: "United States"
console.log(regionNamesInTraditionalChinese.of("US"));
// Expected output: "美國"
of(code)
codeThe code to provide depends on the type:
code should be either a two-letter ISO 3166 region code, or a three-digit UN M49 geographic region. It is required to follow the unicode_region_subtag grammar. Use uppercase codes (e.g., "US"), because lowercase ones (e.g., "us") may not work reliably everywhere.code should be a four-letter ISO 15924 script code. It is required to follow the unicode_script_subtag grammar.code should be matched by the unicode_language_id nonterminal.code should be a three-letter ISO 4217 currency code. It is required to have exactly three alphabetic characters.code should be one of: "era", "year", "quarter", "month", "weekOfYear", "weekday", "day", "dayPeriod", "hour", "minute", "second", "timeZoneName".code should be a calendar key. It is required to follow the type grammar of a Unicode locale identifier.A language-specific formatted string, or undefined if there's no data for the input and fallback is "none".
Note: fallback is only used if code is structurally valid. See using fallback.
RangeErrorThrown if code is not structurally valid for the given type.
const regionNames = new Intl.DisplayNames("en", { type: "region" });
regionNames.of("419"); // "Latin America"
const languageNames = new Intl.DisplayNames("en", { type: "language" });
languageNames.of("fr"); // "French"
const currencyNames = new Intl.DisplayNames("en", { type: "currency" });
currencyNames.of("EUR"); // "Euro"
const languageNamesStandard = new Intl.DisplayNames("fr", {
type: "language",
languageDisplay: "standard",
});
languageNamesStandard.of("fr-CA"); // "français (Canada)"
const languageNamesDialect = new Intl.DisplayNames("fr", {
type: "language",
languageDisplay: "dialect",
});
languageNamesDialect.of("fr-CA"); // "français canadien"
When the Intl.DisplayNames is constructed with fallback: "code", the of() method will return the code if the input looks structurally valid but there's no data for the input. If fallback is "none", undefined is returned.
console.log(
new Intl.DisplayNames("en", { type: "region", fallback: "code" }).of("ZL"),
); // "ZL"
console.log(
new Intl.DisplayNames("en", { type: "region", fallback: "none" }).of("ZL"),
); // undefined
However, this only applies if the code is structurally valid. For example, if type is "region" but code does not follow the unicode_region_subtag grammar (2 alphabetic characters or 3 numeric characters), a RangeError is directly thrown instead of using the fallback.
console.log(
new Intl.DisplayNames("en", { type: "region", fallback: "code" }).of("ZLC"),
); // throws RangeError: invalid value "ZLC" for option region
| Desktop | Mobile | Server | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | Bun | Deno | Node.js | |
of |
81 | 81 | 86 | 68 | 14.1 | 81 | 86 | 58 | 14.5 | 13.0 | 81 | 14.5 | 1.0.0 | 1.8 | 14.0.0 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/of