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.
Output:
Example2: Converting an array ‘season’ into string form.
Output:
Example3: Converting an array containing numeric values into string.
Output:
Example4: We can also represent a user-defined array into string format. Let’s see in this example.
Output:
After entering the array size in the textbox and elements in the prompt box:
Example5: Let’s convert a pre-defined array into string through this example.
Output:
After clicking on the ‘convert’ button, array converts into string.