Table of Contents

Array.join( ) Method Flash 5

convert an array to a string
array.join()
array.join(delimiter)

Arguments

delimiter

An optional string to be placed between elements in the newly created string. Defaults to a comma if not supplied.

Returns

A string composed of all the elements of array, converted to strings and separated by delimiter.

Description

The join( ) method returns a string created by combining all the elements of an array, as follows:

  1. Convert each element in the array to a string according to the rules specified in Table 3-2 in Chapter 3.

  2. Add delimiter to the end of each converted-element string, except the last one.

  3. Concatenate the converted-element strings into one long string.

Note that elements that are themselves arrays are converted to strings via the toString( ) method, so nested array elements are always delimited by commas, not by the delimiter used in the join( ) invocation.

Example

fruit = new Array("apples","oranges","bananas","grapes","plums");
// Set fruitString to "apples,oranges,bananas,grapes,plums"
// (default delimiter is a comma with no following space)
fruitString = fruit.join();
// Use ", " as the delimiter to create nicer formatting than toString( )
// and set fruitString to "apples, oranges, bananas, grapes, plums" (with a
// space after each comma)
fruitString = fruit.join(", ");

See Also

Array.toString( ), String.split( ); "The join( ) Method," in Chapter 11


Table of Contents