JavaScript Array toLocaleString() Method
Last Updated :
15 Jul, 2024
Improve
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
Example 1: In this example, we will see the conversion of a number and a date into strings using array.toLocaleString() function.
// taking inputs.
let name = "geeksforgeeks";
let number = 567;
// It will give current date and time.
let date = new Date();
// Here A is an array containing elements of above variables.
let A = [name, number, date];
// applying array.toLocaleString function.
let string = A.toLocaleString();
// printing string.
console.log(string);
Output
geeksforgeeks,567,7/12/2024, 5:30:59 PM
Example 2: In this example, we will see the conversion of an array and a decimal number into string values using array.toLocaleString() function.
// taking inputs.
let name = ["Ram", "Sheeta", "Geeta"];
let number1 = 3.45;
let number2 = [23, 34, 54];
// Here A is an array containing elements of above variables.
let A = [name, number1, number2];
// applying array.toLocaleString function.
let string = A.toLocaleString();
// printing string.
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 Browsers:
- Google Chrome 1
- Firefox 1
- Opera 4
- Safari 1