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.

arrayReduce(array, function(result, item [,index, array])[, initialValue]) → returns any

Member Function Syntax

someArray.reduce(function(result, item [,index, array])[, initialValue])

arrayReduce Argument Reference

array array

the input array

callback function

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 any

Initial value which will be used for the reduce operation. The type is any.

Links more information about arrayReduce

Examples sample code invoking the arrayReduce function

complexData = [ {a: 4}, {a: 18}, {a: 51} ]; 
 sum = arrayReduce( complexData, function(prev, element) 
 return prev + element.a; 
 }, 0 ); 

Expected Result: Answer: [73]

Fork me on GitHub