Iterates over each item of the list and calls the closure to work on the item. This function will reduce the list to a single value and will return the value.

listReduce(list, function(result, item [,index, list]) [,initialValue, delimiter, includeEmptyFields]) → returns Any

This function requires Adobe ColdFusion 11 and up. Not supported on Lucee, OpenBD, etc.

Argument Reference for the listReduce function


Required: Yes
Input list


Required: Yes
Closure or a function reference that will be called for each of the iteration. The arguments passed to the callback are

item: value
index : current index for the iteration
list : reference of the original list


Required: No
Initial value which will be used for the reduce operation. The type is any.


Required: No
Default: comma
The list delimiter.


Required: No
Default: false
Include empty values.

Links more information about listReduce

Examples sample code invoking the listReduce function

Script Syntax

numbers = "1,2,3,4,5,6,7,8,9,10"; 
 sum = listReduce(numbers, function(previousValue, value) 
 return previousValue + value; 
 },  0); 
 writeOutput("The sum of the digits #numbers# is #sum#<br>"); 

Fork me on GitHub