listReduce

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

Argument Reference

list string
Required

Input list

function any
Required

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

intialValue any

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

delimiter string
Default: comma

The list delimiter.

includeEmptyFields boolean
Default: false

Include empty values.

Links more information about listReduce

Examples
Sample code invoking the listReduce function

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>"); 

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub