JavaScript Array toString() Method

The toString() method is used for converting and representing an array into string form. It returns the string containing the specified array elements. Commas separate these elements, and the string does not affect the original array.

Syntax

The following syntax represents the toString() method:

Parameters

It does not have any parameters.

Return

It returns a string that contains all the elements of the specified array.

JavaScript toString() Method Examples

Let's implement some examples to understand the toString() method better:

Example1: Converting a given array into string form seperated by commas.

Test it Now

Output:

JavaScript Array toString() Method

Example2: Converting an array 'season' into string form.

Test it Now

Output:

JavaScript Array toString() Method

Example3: Converting an array containing numeric values into string.

Test it Now

Output:

JavaScript Array toString() Method

Example4: We can also represent a user-defined array into string format. Let's see in this example.

Test it Now

Output:

After entering the array size in the textbox and elements in the prompt box:

JavaScript Array toString() Method

Example5: Let's convert a pre-defined array into string through this example.

Test it Now

Output:

JavaScript Array toString() Method

After clicking on the 'convert' button, array converts into string.






Latest Courses