Intl.Locale.prototype.toString()

The Intl.Locale.prototype.toString() returns the Locale's full locale identifier string.

Syntax

locale.toString()

Return value

The locale's Unicode locale identifier string.

Description

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.

Examples

let myLocale = new Intl.Locale("fr-Latn-FR", {hourCycle: "h24", calendar: "gregory"});
console.log(myLocale.baseName); // Prints "fr-Latn-FR"
console.log(myLocale.toString()); // Prints "fr-Latn-FR-u-ca-gregory-hc-h24" 

Specifications

Specification Status Comment
Intl.Locale.prototype.toString proposal Stage 3

Browser compatibility

Update compatibility data on GitHub
Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js
toString Chrome Full support 74 Edge No support No Firefox No support No IE No support No Opera No support No Safari No support No WebView Android Full support 74 Chrome Android Full support 74 Firefox Android No support No Opera Android No support No Safari iOS No support No Samsung Internet Android No support No nodejs No support No

Legend

Full support  
Full support
No support  
No support

See also