This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The toLocaleString() method of Array instances returns a string representing the elements of the array. The elements are converted to strings using their toLocaleString methods and these strings are separated by a locale-specific string (such as a comma ",").
const array = [1, "a", new Date("21 Dec 1997 14:12:00 UTC")];
const localeString = array.toLocaleString("en", { timeZone: "UTC" });
console.log(localeString);
// Expected output: "1,a,12/21/1997, 2:12:00 PM",
// This assumes "en" locale and UTC timezone - your results may vary
toLocaleString() toLocaleString(locales) toLocaleString(locales, options)
locales OptionalA string with a BCP 47 language tag, or an array of such strings. For the general form and interpretation of the locales argument, see the parameter description on the Intl main page.
options OptionalAn object with configuration properties. What you can pass here depends on what elements are being converted. For example, for numbers, see Number.prototype.toLocaleString().
A string representing the elements of the array.
The Array.prototype.toLocaleString method traverses its content, calling the toLocaleString method of every element with the locales and options parameters provided, and concatenates them with an implementation-defined separator (such as a comma ",").
Note: The locales or options arguments do not control the separator used between array elements; they are simply passed to the toLocaleString() method of each element. The actual separator (usually a comma) depends solely on the host's current locale. If you expect localized list formatting, consider using Intl.ListFormat instead.
If an element is undefined, null, it is converted to an empty string instead of the string "null" or "undefined".
When used on sparse arrays, the toLocaleString() method iterates empty slots as if they have the value undefined.
The toLocaleString() method is generic. It only expects the this value to have a length property and integer-keyed properties.
The elements of the array are converted to strings using their toLocaleString methods. For example, this snippet implicitly calls the Number.prototype.toLocaleString() method to display the currency for the strings and numbers in the prices array:
const prices = ["¥7", 500, 8123, 12];
prices.toLocaleString("ja-JP", { style: "currency", currency: "JPY" });
// "¥7,¥500,¥8,123,¥12"
The list separator is not affected by the locales parameter. To configure it, use Intl.ListFormat instead.
const nums = [8888, 9999];
console.log(nums.toLocaleString("zh")); // "8,888,9,999"
const formatter = new Intl.ListFormat("zh", {
type: "conjunction",
style: "narrow",
});
console.log(formatter.format(nums.map((x) => x.toLocaleString("zh"))));
// "8,888、9,999"
toLocaleString() treats empty slots the same as undefined and produces an extra separator:
console.log([1, , 3].toLocaleString()); // '1,,3'
The toLocaleString() method reads the length property of this and then accesses each property whose key is a nonnegative integer less than length.
const arrayLike = {
length: 3,
0: 1,
1: 2,
2: 3,
3: 4, // ignored by toLocaleString() since length is 3
};
console.log(Array.prototype.toLocaleString.call(arrayLike));
// 1,2,3
| 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 | |
toLocaleString |
1 | 12 | 1 | 4 | 1 | 18 | 4 | 10.1 | 1 | 1.0 | 1 | 1 | 1.0.0 | 1.0 | 0.10.0 |
locales_parameter |
24 | 79 | 52 | 15 | 7 | 25 | 56 | 14 | 7 | 2.0 | 4.4 | 7 | 1.0.0 |
1.81.0–1.8Only the locale data foren-US is available. |
13.0.00.12.0–13.0.0Before version 13.0.0, only the locale data foren-US is available by default. When other locales are specified, the function silently falls back to en-US. To make full ICU (locale) data available before version 13, see Node.js documentation on the --with-intl option and how to provide the data. |
options_parameter |
24 | 79 | 52 | 15 | 7 | 25 | 56 | 14 | 7 | 2.0 | 4.4 | 7 | 1.0.0 | 1.0 | 0.12.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/Array/toLocaleString