Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

JavaScript | array.toLocaleString() function

  • Last Updated : 18 Nov, 2021

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:
 

JavaScript




// 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);

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:
 

JavaScript




// 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 ];
 
// applying array.toLocaleString function.
var string = A.toLocaleString();
 
// printing string.
console.log(string);

Output: 
 

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

 Supported Browser:

  • Google Chrome 1 and above
  • Internet Explorer 5.5 and above
  • Firefox 1 and above
  • Opera 4  and above
  • Safari 1 and above

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!