Whatever message this page gives is out now! Go check it out!

ListReduce

Last update:
May 18, 2026
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

Syntax

ListReduce(list, callback, initialValue, [delimiter, includeEmptyFields])
History
ColdFusion (2018 release): Introduced named parameters.
ColdFusion 11: Added this function.

Parameters

Parameter
Req/Opt
Default
Description
listRequired The input list.
callbackRequired 
Closure or a function reference that will be called for each iteration. The arguments passed to the callback are
  • result : This function reduces the list to a single value and returns the value. The value is stored in result.
  • item: value
  • index: current index for the iteration
  • list: reference of the original list
  • delimiter: the delimiter to be passed into the callback. The default is comma (,).
initialValueOptional Initial value which will be used for the reduce operation. The type is any.
delimiterOptionalcomma (,)The list delimiter. The type is string .
includeEmptyFieldsOptionalfalseInclude empty values. The type is boolean.
Example
<cfscript>
       myList="23,54,87,98,11,35,91";
       closure=function(value1,value2){
             return (value1+value2/ListLen(myList)); // Calculates the average of the values in the list
       }
       MyVal=ListReduce(myList,closure,0); // Initial value is 0
       WriteOutput(#myVal#);
</cfscript>
Output
57

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page