We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Allow to sum collection values by using given iterator.
var myArray = [ { productId: 1, title: 'My Product 1', price: 10, quantity: 1 }, { productId: 2, title: 'My Product 2', price: 15.5, quantity: 3 }, { productId: 3, title: 'My Product 3', price: 7.25, quantity: 1 } ];
var numberOfArticles = _.sum(myArray, function(obj) { return obj.quantity; }); // numberOfArticles === 5
var total = _.sum(myArray, function(obj) { return obj.price * obj.quantity; }); // total === 63.75