toString

Returns a string representing the specified object.

Applies to

Array

Syntax

toString()

Parameters

None

Description

Every object has a toString method that is automatically called when it is to be represented as a text value or when an object is referred to in a string concatenation.

You can use toString within your own code to convert an object into a string, and you can create your own function to be called in place of the default toString method.

For Array objects, the built-in toString method joins the array and returns one string containing each array element separated by commas. For example, the following code creates an array and uses toString to convert the array to a string while writing output.

var monthNames = new Array("Jan","Feb","Mar","Apr")
Console.Write("monthNames.toString() is " + monthNames.toString())

The output is as follows:

monthNames.toString() is Jan,Feb,Mar,Apr

For information on defining your own toString method, see the Object: toString method.