JavaScript Array toLocaleString() Method

The toLocaleString() method creates a string that represents the elements of an array.

Syntax

arr.toLocaleString(locales, options)
  • locales (optional) – A string with a BCP 47 language tag, or an array of such strings. To learn more, visit Intl – JavaScript.
  • options (optional) – An object with configuration properties.

Return value

A string representing the elements of the array.

Examples

let array = [1, "JavaScript", new Date()];

let string = array.toLocaleString();
console.log(string); // 1,JavaScript,7/29/2020, 1:53:29 PM

let prices = [689, 100, 4577, 56];

// Using locales and options
// using Nepali Ruppes currency string format
let string1 = prices.toLocaleString("ne-NP", {
  style: "currency",
  currency: "NPR",
});

console.log(string1); // NPR 689.00,NPR 100.00,NPR 4,577.00,NPR 56.00
const array1 = [1, 'a', new Date('21 Dec 1997 14:12:00 UTC')];
const localeString = array1.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