ListEach
Used to iterate over a delimited list and run the function closure for each item in the list.
Method Signature
Arguments
list
string
true
The delimited list to perform operations on
callback
function:Consumer
true
The function to invoke for each item. The function will be passed 3 arguments: the value, the index, the array. You can alternatively pass a Java Consumer which will only receive the 1st arg.
delimiter
string
false
string the list delimiter
,
includeEmptyFields
boolean
false
boolean whether to include empty fields in the returned result
false
multiCharacterDelimiter
boolean
false
boolean whether the delimiter is multi-character
true
parallel
boolean
false
Specifies whether the items can be executed in parallel
false
maxThreads
integer
false
The maximum number of threads to use when parallel = true
ordered
boolean
false
(BoxLang only) whether parallel operations should execute and maintain order
false
Examples
List Loop using listEach
Using a semicolon delimiter.
Result: 1:a;2:b;3:c;
Member Function Example
List Loop list.listEach()
Result: 1:a;2:b;3:c;
Example using a Closure
Example 1
Result: john at index: 1pete at index: 2bob at index: 3'john' at index: 1 'pete' at index: 2 'bob' at index: 3
Another Closure Example
Example 2
Result: Current city: PittsburghCurrent city: RaleighCurrent city: MiamiCurrent city: Las Vegas
Additional Examples
Related
Last updated
Was this helpful?