The toLocaleString()
method of Object
instances returns a string representing this object. This method is meant to be overridden by derived objects for locale-specific purposes.
The toLocaleString()
method of Object
instances returns a string representing this object. This method is meant to be overridden by derived objects for locale-specific purposes.
None. However, all objects that override this method are expected to accept at most two parameters, corresponding to locales
and options
, such as Date.prototype.toLocaleString
. The parameter positions should not be used for any other purpose.
The return value of calling this.toString()
.
All objects that inherit from Object.prototype
(that is, all except null
-prototype objects) inherit the toLocaleString()
method. Object
's toLocaleString
returns the result of calling this.toString()
.
This function is provided to give objects a generic toLocaleString
method, even though not all may use it. In the core language, these built-in objects override toLocaleString
to provide locale-specific formatting:
Array.prototype.toLocaleString()
is used to print array values as a string by invoking each element's toLocaleString()
method and joining the results with a locale-specific separator. For example:
Date.prototype.toLocaleString()
is used to print out date displays more suitable for specific locales. For example:
Number.prototype.toLocaleString()
is used to print out number displays more suitable for specific locales, e.g. with the correct separators. For example:
Desktop | Mobile | Server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | Deno | Node.js | ||
toLocaleString |
1 | 12 | 1 | 4 | 1 | 18 | 4 | 10.1 | 1 | 1.0 | 4.4 | 1.0 | 0.10.0 |
© 2005–2023 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/Object/toLocaleString