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:
// 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:
// 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); |
Output:
> "Ram, Sheeta, Geeta, 3.45, 23, 34, 54"
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- JavaScript | toPrecision( ) Function
- JavaScript | Math.abs( ) function
- JavaScript | Function Definitions
- JavaScript | Function Call
- JavaScript | toFixed( ) Function
- JavaScript | Array.of() function
- JavaScript | toString( ) function
- Javascript | Number() Function
- JavaScript | Math.E() function
- JavaScript | toExponential() Function
- JavaScript | Function Invocation
- JavaScript | Array every() function
- JavaScript | Math.pow( ) Function
- JavaScript | Function Parameters
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.



