JavaScript | array.toLocaleString() function

The array.toLocaleString() is an inbuilt function in JavaScript which is basically used to convert the element of the given array to string.
Syntax:

arr.toLocaleString();

Return values:
It return a string representing the elements of the array.
JavaScript Version:
ECMAScript 1
Examples:

Input: 
var name = "gfg";
var number = 123;
var A = [ name, number ];
Output:
> "gfg, 123"

Here as we see that in input there are two variables containing elements but in output these are converted into a string.
Let’s see JavaScript program on array.toLocaleString() function:

filter_none

edit
close

play_arrow

link
brightness_4
code

// taking inputs.
var name = "geeksforgeeks";
var number = 567;
  
// It will give current date and time.
var date = new Date();
  
// Here A is an array containing elements of above variables.
var A = [ name, number, date ];
  
// applying array.toLocaleString function.
var string = A.toLocaleString();
  
// printing string.
console.log(string);

chevron_right


Output:

> "geeksforgeeks, 567, 2/18/2018, 10:41:20 AM"

Application:
The array.toLocaleString() function in JavaScript is used whenever we need to convert the element of the given array to a string.
Let’s see JavaScript program on array.toLocaleString() function:

filter_none

edit
close

play_arrow

link
brightness_4
code

// taking inputs.
var name = [ "Ram", "Sheeta", "Geeta" ];
var number1 = 3.45;
var number2 = [ 23, 34, 54 ];
  
// Here A is an array containing elements of above variables.
var A = [ name, number1, number2 ];
  
// appling array.toLocaleString function.
var string = A.toLocaleString();
  
// printing string.
console.log(string);

chevron_right


Output:

> "Ram, Sheeta, Geeta, 3.45, 23, 34, 54"


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.