Laatst bijgewerkt op 
                
                    20 jan. 2022
                
            
            
                 | 
                
                    Ook van toepassing op ColdFusion
                
            
        
        
            
        
    
Description
Iterates over every element of a List object and can call a UDF function, passed as the second argument.
Returns
None
History
ColdFusion (2018 Release): Made the following changes:
- Parameter str is renamed to list
- Parameter function is renamed to closure
- Parameter delim is renamed to delimiters
Category
Syntax
ListEach(String list, UDFMethod closure [, String delimiters, boolean includeEmptyFields])
Parameters
| Parameter | Description | 
|---|---|
| list | An input list object. | 
| closure | UDF or closure object. | 
| delimiters | 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