Table of Contents

Array.toString( ) Method Flash 5

convert an array to a string of comma-separated element values
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 invoked automatically whenever the array is used in a string context. Therefore, it is rarely necessary to invoke toString( ) manually. Normally, when we want a precise string representation of an array, we use the join( ) method, which offers 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( )


Table of Contents