JavaScript Array.prototype.toString() Method
The toString() method returns a string of an array's elements separated by commas.
Description
The toString() method returns the elements joined by commas, the same as join() with no argument. JavaScript calls it automatically when an array is used where a string is expected, such as in string concatenation. For a readable representation of nested data, JSON.stringify() is usually more useful.
For arrays, toString() is equivalent to join(','): null and undefined elements become empty strings and nested arrays are flattened into the same comma-separated list, which loses their structure. Objects inside become "[object Object]".
You'll mostly encounter it indirectly, when an array is concatenated with a string or put inside a template literal, or when it's used as an object key. When you need a specific separator, call join(), and when you need to keep the data's structure, use JSON.stringify().
Syntax
array.toString()Return Value
A string of the elements separated by commas.
Example
Browser Support
The following information will show you the current browser support for the Array.prototype.toString() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





