Whatever message this page gives is out now! Go check it out!
ArrayReduce(array, callback,[ initialValue=null]) |
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
| |
| initialValue | Optional | Initial value which will be used for the reduce operation. The type is any. |
<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>