Visit Mozilla.org

Core JavaScript 1.5 Reference:Global Objects:Array:toString

From MDC


Contents

[edit] Summary

Returns a string representing the specified array and its elements.

Method of Array
Implemented in: JavaScript 1.1, NES 2.0
ECMA Version: ECMA-262

[edit] Syntax

toString()

[edit] Parameters

None.

[edit] Description

The Array object overrides the toString method of Object. For Array objects, the 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.

var monthNames = new Array("Jan","Feb","Mar","Apr");
myVar = monthNames.toString(); // assigns "Jan,Feb,Mar,Apr" to myVar

JavaScript calls the toString method automatically when an array is to be represented as a text value or when an array is referred to in a string concatenation.

[edit] See Also

toSource