Iterates over every entry of the given array and calls the closure with every element. This function will reduce the array to a single value and will return the value.

ArrayReduce( array, closure [, initalValue ] )

Returns: any

Argument Description
array, required

array to iterate

function, required

function/closure that implements the following constructor [function(any result, object value, [, numericindex [, array]]):any].

object, optional

inital value passed as part of the first closure call


reduced = ArrayReduce( [1,2,3,4], function( carry, value ){ 
    return carry + value;
}, 0 );
dump( reduced ); // yields 10
reduced = ArrayReduce( ['hello', 'there', 'lucee'], function(carry, value){
    return carry & ' ' & value;
}, '' );
dump( reduced ); // yields 'hello there lucee'

See also