Home » JavaScript Array toLocaleString() Method

JavaScript Array toLocaleString() Method

by Online Tutorials Library

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.

Test it Now

Output:

The output is shown below:

JavaScript Array toLocaleString() Method

In the output, the array is represented in the form of string.

Example2

Here’s an example that implements date() method with toLocaleMethod().

Test it Now

Output:

JavaScript Array toLocaleString() Method

Example3

Implementing the above example on the console.

Test it Now

Output:

JavaScript Array toLocaleString() Method

Example4

Implementing an example that combines the array elements and a value together into a new array.

Test it Now

Output:

The output comes out as:

JavaScript Array toLocaleString() Method


Next TopicJavaScript Array

You may also like