Name

Array.toString ( ) Method — convert an array to a string of comma-separated element values

Availability

Flash 5

Synopsis

array.toString( )

Returns

A comma-separated list of array’s elements converted to strings.

Description

The toString( ) method creates a string representation of array. The string returned by toString( ) is a list of array elements converted to strings and separated by commas (the same as is returned by the join( ) method when join( ) is invoked without parameters). An array’s toString( ) method is automatically invoked whenever the array is used in a string context. Therefore, it is rarely necessary to manually execute toString( ) on an array. Normally, when we want a precise string representation of an array, we use the join( ) method, which offers us more control over the string we’re creating.

Example

myList = new Array("a", "b", "c");             // Create an array
trace(myList.toString( ));                      // Displays: "a","b","c"
myList = new Array([1, 2, 3], "a", "b", "c");  // Create a nested array
trace(myList.toString( ));                      // Displays: "1,2,3,a,b,c"

See Also

Array.join( )

Get ActionScript: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.