toLocaleString Method

Returns a value as a string value appropriate to the host environment's current locale.

function toLocaleString() : String

For the Array object, the elements of the array are converted to strings and these strings are concatenated and returned, each separated by the list separator specified for the host environment's current locale.

For the Date object, the toLocaleString method returns a String object that contains the date written in the current locale's long default format.

  • For dates between 1601 and 9999 A.D., the date is formatted according to the user's Control Panel Regional Settings.

  • For dates outside this range, the default format of the toString method is used.

For the Number object, toLocaleString produces a string value that represents the value of the Number formatted as appropriate for the host environment's current locale.

For Object objects, ToLocaleString is provided to give all objects a generic toLocaleString capability, even though they may not use it.


toLocaleString should only be used to display results to a user; it should never be used as the basis for computation within a script as the returned result is machine-specific.

The following client-side example illustrates the use of the toLocaleString method using an Array, a Date, and a Number object.

function toLocaleStringArray() {
   // Populate an array with values.
   // Each value is the same as the index.
   var myArray = new Array();
   for(var i = 0; i <= 6; i++)
      myArray[i] = i;

   var s = myArray.toLocaleString();

function toLocaleStringDate() {
   var d = new Date();
   var s = d.toLocaleString();

function toLocaleStringNumber() {
   var n = Math.PI;
   var s = n.toLocaleString();

Other Resources

Community Additions