The Javascript array.toLocaleString() is an inbuilt function in JavaScript that is basically used to convert the elements of the given array to a string.
Syntax:
arr.toLocaleString(locales, options)
Return values: It returns a string representing the elements of the array.
JavaScript Version: ECMAScript 1
Examples: In this example, the variable number will be converted into a string using the array.toLocaleString() function.
Input:
let name = "gfg";
let number = 123;
let 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 the JavaScript program on array.toLocaleString() function:
Example: In this example, we will see the conversion of a number and a date into strings using array.toLocaleString() function.
JavaScript
let name = "geeksforgeeks" ;
let number = 567;
let date = new Date();
let A = [name, number, date];
let string = A.toLocaleString();
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 elements of the given array to a string.
Let’s see the JavaScript program on array.toLocaleString() function:
Example: In this example, we will see the conversion of an array and a decimal number into string values using array.toLocaleString() function.
JavaScript
let name = [ "Ram" , "Sheeta" , "Geeta" ];
let number1 = 3.45;
let number2 = [23, 34, 54];
let A = [name, number1, number2];
let string = A.toLocaleString();
console.log(string);
|
Output:
"Ram, Sheeta, Geeta, 3.45, 23, 34, 54"
We have a complete list of Javascript Array methods, to check those please go through this Javascript Array Complete reference article.
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
We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
25 May, 2023
Like Article
Save Article