Description

Iterates over every element of a List object and can call a UDF function, passed as the second argument.

Returns

None

Category

List functions

Syntax

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.

Also, the original array can also be passed to the closure function. So the following code is also valid:

...
function xclosure(empname, index, empArray)
{
 
}
...

Example 1

<cfscript>
    cityList = "San Jose,New York, Boston, Las Vegas";
    function printCity(String city)
    {
        WriteOutput("<br>Current city: " & city);
    }
    ListEach(cityList ,printCity);
</cfscript>

Output

Current city: San Jose
Current city: New York
Current city: Boston
Current city: Las Vegas

Example 2

<cfscript>
       myList="Tokyo,Bangkok,Jakarta,Manila,Bangalore,Shanghai";
       ListEach(myList,function(myListElement,index,myList){
             WriteOutput("#index#:#myListElement#" & " ");
             });
</cfscript>

Output

1:Tokyo 2:Bangkok 3:Jakarta 4:Manila 5:Bangalore 6:Shanghai

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy