ListEach()
call the given UDF/Closure with every value in the string list.
ListEach( list=string, closure=function, delimiter=string, includeEmptyFields=boolean, multiCharacterDelimiter=boolean, parallel=boolean, maxThreads=number );
Returns: void
Argument | Description | Default |
---|---|---|
list
string,
required
|
string list to iterate |
|
closure
function,
required
|
function/closure that implements the following constructor
Alias: function, callback, udf |
|
delimiter
string,
optional
|
delimiter used to separate the string list |
, |
includeEmptyFields
boolean,
optional
|
include empty fields or not |
false |
multiCharacterDelimiter
boolean,
optional
|
specify whether the delimiters parameter is a multi-character delimiter. If this parameter is true, the delimiters parameter must specify a single delimiter consisting of multiple characters. This parameter enables the ListToArray() function to convert a list such as the following to an array of color names: red:|orange:|yellow:|green:|blue:|indigo:|violet. |
true |
parallel
boolean,
optional
|
execute closures parallel |
false |
maxThreads
number,
optional
|
maximum number of threads executed, ignored when argument "parallel" is set to false Alias: maxThreadCount |
20 |
Examples
list = "Plant,green,save,earth";
listEach(list, function(element,index,list) {
writeOutput("#index#:#element#;<br>");
});
<span class="c">//Member function with custom delimiter</span>
<span class="nf">writeOutput</span><span class="p">(</span><span class="s2">"<br>Member Function<br>"</span><span class="p">);</span>
<span class="nv">strLst</span><span class="o">=</span><span class="s2">"one+two+three"</span><span class="p">;</span>
<span class="nf">strLst.listEach</span><span class="p">(</span><span class="nf">function</span><span class="p">(</span><span class="nv">element</span><span class="p">,</span><span class="nv">index</span><span class="p">,</span><span class="nv">list</span><span class="p">)</span> <span class="p">{</span>
<span class="nf">writeOutput</span><span class="p">(</span><span class="s2">"</span><span class="s-Interp">#index#</span><span class="s2">:</span><span class="s-Interp">#element#</span><span class="s2">;<br>"</span><span class="p">);</span>
<span class="p">},</span><span class="s2">"+"</span><span class="p">);</span>
See also
- Collections
- Lists
- Strings
- Threads
- string.listEach()
- Search Issue Tracker
- Search Lucee Test Cases (good for further, detailed examples)