Name

Array.join( ) Method — convert an array to a string

Availability

Flash 5

Synopsis

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 (empty elements are converted to the empty string).

  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 the delimiter used in the join( ) invocation.

Example

fruit = new Array("apples","oranges","bananas","grapes","plums");
// Set fruitString to "apples,oranges,bananas,grapes,plums"
fruitString = fruit.join( );
// Set fruitString to "apples-oranges-bananas-grapes-plums"
fruitString = fruit.join("-");

See Also

Array.toString( ), String.split( ) ; Section 11.9.4 in Chapter 11

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.