Sum amount of an item value for every item
collectionReduce(collection, closure [, initialValue])
→ returns any
coll = [{
id: 0,
type: 'apples',
amount: 25
},{
id: 1,
type: 'pinapples',
amount: 2
},{
id: 2,
type: 'peaches',
amount: 13
}];
fruits = collectionReduce(coll,function(a,b) {
return a + b.amount;
},0);
writeOutput(fruits&' fruits');
Expected Result: 40 fruits
Signup for cfbreak
to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.