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

ArrayReduce

Last update:
May 18, 2026
Description
Iterates over every entry of the array and calls the closure to work on the elements of the array. This function will reduce the array to a single value and will return the value.

Returns

Any

Syntax

ArrayReduce(array, callback,[ initialValue=null])

History

ColdFusion (2018 release): Changed parameter function to callback.
ColdFusion 11: Added this function.

Parameters

Parameter
Req/Opt
Default
Description
arrayRequired The input array.
callbackRequired 
Closure or a function reference that will be called for each of the iteration . The arguments passed to the callback are
  • result: result of the reduce operation after the previous iteration
  • item: item in the array
  • index : current index for the iteration
  • array : reference of the original array
initialValueOptional Initial value which will be used for the reduce operation. The type is any.

Example

<cfscript>
 

arr = [1,2,3,4,5];
 

function square(element, index)

{

writeOutput("index is " & index);

return element * element;

}
 
 

sq = arrayMap(arr, square);

writeDump(sq);
 

result = arrayReduce(sq, function(value, element)

{

value = value?:0;

value += element;

return value;

});
 

writeDump(result);
 

</cfscript>

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