ArrayReduce

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

array Required   The input array.
callback Required  

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
initialValue Optional   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>

 Adobe

Få hjelp raskere og enklere

Ny bruker?

Adobe MAX 2024

Adobe MAX
Kreativitetskonferansen

14.–16. oktober, Miami Beach og på nettet

Adobe MAX

Kreativitetskonferansen

14.–16. oktober, Miami Beach og på nettet

Adobe MAX 2024

Adobe MAX
Kreativitetskonferansen

14.–16. oktober, Miami Beach og på nettet

Adobe MAX

Kreativitetskonferansen

14.–16. oktober, Miami Beach og på nettet