Name

Array.toString() — convert an array to a string

Inherits from

Overrides Object.toString()

Synopsis

array.toString()

Returns

A string representation of array.

Throws

TypeError

If this method is invoked on an object that is not an Array.

Description

The toString() method of an array converts an array to a string and returns the string. When an array is used in a string context, JavaScript automatically converts it to a string by calling this method. On some occasions, however, you may want to call toString() explicitly.

toString() converts an array to a string by first converting each array element to strings (by calling its toString() method). Once each element is converted to a string, toString() outputs them in a comma-separated list. This return value is the same string that would be returned by the join() method with no arguments.

Get JavaScript: The Definitive Guide, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.