Description
Iterates over every element of a List object and can call a UDF function, passed as the second argument.
Returns
None
Description
Iterates over every element of a List object and can call a UDF function, passed as the second argument.
None
ListEach(String str, UDFMethod function [, String delim, boolean includeEmptyFields])
Parameters
Parameter |
Description |
---|---|
str |
An input list object. |
function |
UDF or closure object. |
delim | A list delimiter to be used. The default value is comma (,). |
includeEmptyFields | Boolean. Whether to allow empty fields. Default is false. |
Example 1
<cfscript> empArray = ["awdhesh", "kumar", "agrawal"]; listS = "'awdhesh', 'kumar', 'agrawal'"; ArrayEach(empArray, xclosure); ListEach(listS, xclosure); function xclosure(empname, index) { writeOutput(empName & " at index: " & index); } </cfscript>
Also, the original array can also be passed to the closure function. So the following code is also valid:
... function xclosure(empname, index, empArray) { } ...
<cfscript> cityList = "San Jose,New york, Boston, Las Vegas"; function printCity(String city) { writeOutput("<br>Current city: " & city); } ListEach(cityList ,printCity); </cfscript>