Description
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.
Returns
any
Description
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.
any
ListReduce(list, function(result, item [,index, list]) [,initialValue, delimiter, includeEmptyFields])
History
ColdFusion 11: Added this function.
Attribute |
Req/Opt |
Default |
Description |
---|---|---|---|
list | Required | The input list. | |
function | Required | Closure or a function reference that will be called for each of the iteration. The arguments passed to the callback are
|
|
initialValue | Optional | Initial value which will be used for the reduce operation. The type is any. | |
delimter | Optional | comma (,) | The list delimiter The type is string.. |
includeEmptyFields | Optional | false | Include empty values. The type is boolean. |
Example
<cfscript> list = "red, blue, green, yellow"; ucaseList = listMap(list, function(item) { return ucase(item); }); writeDump(ucaseList); writeOutput("<br>"); concatValues = listReduce(list, function(result, item, index, mylist, delimiter) { result = result?:""; if(index == 1) delimiter = ""; result&= delimiter & item; return result; }); writeDump(concatValues); </cfscript>