O'Reilly logo

Essential ActionScript 3.0 by Colin Moock

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Checking the Contents of an Array with the toString( ) Method

The toString( ) method, common to all objects, returns a string representation of the object upon which it is invoked. In the case of an Array object, the toString( ) method returns a list of the array's elements, converted to strings and separated by commas. The toString( ) method can be called explicitly, as follows:

theArray.toString()

Typically, however, toString( ) isn't used explicitly; rather, it is invoked automatically whenever theArray is used in a string context. For example, the expression trace(theArray) outputs a list of comma-separated element values during debugging; trace(theArray) is equivalent to trace(theArray.toString( )). The toString( ) method is often helpful during debugging when we need a quick, unformatted look at the elements of an array. For example:

var sites = ["www.moock.org", "www.adobe.com", "www.oreilly.com"];
trace("The sites array is " + sites);

Note that the join( ) method offers greater formatting flexibility than toString( ). For details, see Adobe's ActionScript Language Reference.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required