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:
Convert each element in the array to a string (empty elements are converted to the empty string).
Add
delimiterto the end of each converted-element string, except the last one.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
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access