This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2020.
The toString() method of Intl.Locale instances returns this Locale's full locale identifier string.
const french = new Intl.Locale("fr-Latn-FR", {
calendar: "gregory",
hourCycle: "h12",
});
const korean = new Intl.Locale("ko-Kore-KR", {
numeric: true,
caseFirst: "upper",
});
console.log(french.toString());
// Expected output: "fr-Latn-FR-u-ca-gregory-hc-h12"
console.log(korean.toString());
// Expected output: "ko-Kore-KR-u-kf-upper-kn"
toString()
None.
The locale's Unicode locale identifier string.
The Locale object is a JavaScript representation of a concept Unicode locale identifier. Information about a particular locale (language, script, calendar type, etc.) can be encoded in a locale identifier string. To make it easier to work with these locale identifiers, the Locale object was introduced to JavaScript. Calling the toString method on a Locale object will return the identifier string for that particular Locale. The toString method allows Locale instances to be provided as an argument to existing Intl constructors, serialized in JSON, or any other context where an exact string representation is useful.
const myLocale = new Intl.Locale("fr-Latn-FR", {
hourCycle: "h12",
calendar: "gregory",
});
console.log(myLocale.baseName); // Prints "fr-Latn-FR"
console.log(myLocale.toString()); // Prints "fr-Latn-FR-u-ca-gregory-hc-h12"
| 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 | |
toString |
74 | 79 | 75 | 62 | 14 | 74 | 79 | 53 | 14 | 11.0 | 74 | 14 | 1.0.0 | 1.8 | 12.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/Locale/toString