Array.toString() (Method)

Return a string primitive version of an object.

Availability:

ECMAScript edition - 2
JavaScript - 1.1
JScript - 3.0
Internet Explorer - 4.0
Netscape - 3.0
Netscape Enterprise Server - 2.0
Opera - 3.0
Property/method value type:String primitive
JavaScript syntax:-myArray.toString()

The elements in the array are converted to strings and are concatenated together to form a larger string.

This is functionally identical to using the join() method with no join string argument.

If you run the example, it will yield the following:

one,2,III

This is quite different to what you get if you use the toSource() method which presents this result:

["one", 2, "III"]

The result of this method is a String primitive version of the array assembled by concatenation.

Warnings:

Example code:

   // Create an array and display it as a string

   myObject = new Array("one", 2, "III");

   document.write(myObject.toString());

See also:Array.prototype, Array.toSource(), Cast operator, String concatenate (+), toString()

insert figure 0015

Cross-references:

ECMA 262 edition 2 - section - 15.4.4.2

ECMA 262 edition 3 - section - 15.4.4.2