
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Arrays as Objects
|
269
Typically, we don’t use toString() explicitly; rather, it is invoked automatically when-
ever
arrayName is used in a string context. For example, when we write
trace(
arrayName), a list of comma-separated values appears in the Output window;
trace(
arrayName) is equivalent to trace(arrayName.toString()). The toString() method is
often helpful during debugging when we need a quick, unformatted look at the ele-
ments of an array. For example:
var sites = ["www.moock.org", "www.macromedia.com", "www.oreilly.com"];
// Display our array in a text field
debugOutput_txt.text = "The sites array is " + sites.toString();
trace("The sites array is " + sites.toString()); // Explicit use of toString( )
trace("The sites array is " + sites); // Implicit use of toString( )
The join() method covered in the previous section offers greater formatting flexibil-
ity than toString().
Arrays as Objects
Once you’ve read Chapter 12, you should recognize that arrays are a type of object,
specifically, instances of the Array class. As with other objects, Array objects can
have properties added to them. When we add named elements to an array, we’re
really just adding properties to an Array object. However, as we saw earlier, to use
the built-in methods of the Array class we must work with numbered ...