JavaScript Array toLocaleString() Method
The toLocaleString() method creates a string that represents the elements of an array. It converts the array elements into the string.
Syntax
Parameter
array: It is the given array or the source array.
Including this, there are two optional parameters also.
locales: It is a string that supports BCP 47 language tag, i.e., an IETF code that identifies human language.
Options: It is an object used for dates and numbers basically. They carry their configuration properties with them.
Return
It creates and returns a string that represents the array elements.
JavaScript toLocaleString() Example
Let’s see the below examples to understand better:
Example1
Here’s an example that shows the basic implementation of toLocaleString() method.
Output:
The output is shown below:
In the output, the array is represented in the form of string.
Example2
Here’s an example that implements date() method with toLocaleMethod().
Output:
Example3
Implementing the above example on the console.
Output:
Example4
Implementing an example that combines the array elements and a value together into a new array.
Output:
The output comes out as: