ArrayToList

Used to iterate over an array and run the function closure for each item in the array.

Method Signature

ArrayToList(array=[array], delimiter=[String], initialValue=[any])

Arguments

Argument
Type
Required
Description
Default

array

array

true

The array to join together

delimiter

String

false

The character to use as a separator

,

initialValue

any

false

Examples

Retrieve an array as a list

Uses the arrayToList function with a pipe delimiter to retrieve an array as a list

Run Example

someArray = [ 
	1,
	2,
	3,
	4
];
someList = arrayToList( someArray, "|" );
writeOutput( someList );

Result: "1|2|3|4"

Retrieve an array as a list using the Array member function

Uses the Array member function to retrieve an array as a list

Run Example

seinfeldArray = [ 
	"Jerry",
	"Elaine",
	"Kramer",
	"George"
];
seinfeldList = seinfeldArray.toList();
writeOutput( seinfeldList );

Result: "Jerry,Elaine,Kramer,George"

Additional Examples

Run Example

newArray = [ 
	"a",
	"b",
	"c",
	"b",
	"d",
	"b",
	"e",
	"f"
];
dump( arrayToList( newArray ) );
// member function, with custom separator
dump( newArray.toList( "--" ) );

Last updated

Was this helpful?