Intl.DisplayNames.prototype.of()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2021.

La méthode Intl.DisplayNames.prototype.of() prend comme argument un code et renvoie une chaîne de caractères selon les options et la locale fournies lors de l'instanciation de l'objet Intl.DisplayNames.

Exemple interactif

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: "美國"

Syntaxe

js
of(code);

Paramètres

code

La valeur du code à fournir dépend du type :

Valeur de retour

Une chaîne de caractères formatée spécifique à une locale.

Exemples

Utilisation de la méthode of()

js
let regionNames = new Intl.DisplayNames(["en"], { type: "region" });
regionNames.of("419"); // "Latin America"

let languageNames = new Intl.DisplayNames(["en"], { type: "language" });
languageNames.of("fr"); // "French"

let currencyNames = new Intl.DisplayNames(["en"], { type: "currency" });
currencyNames.of("EUR"); // "Euro"

Spécifications

Specification
ECMAScript® 2025 Internationalization API Specification
# sec-Intl.DisplayNames.prototype.of

Compatibilité des navigateurs

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
of

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

Voir aussi