Method sum documentation

Returns the sum of the given property or function for the array's elements matching the filter.

Example

```javascript let invited = [ {name: "Robert De Niro", attendees: 2, confirmed: true}, {name: "Al Pacino", attendees: 1, confirmed: false}, {name: "James Caan", attendees: 4, confirmed: false}, {name: "Harvey Keitel", attendees: 5, confirmed: true} ]; // No filter bbn.fn.sum(invited, "attendees"); // 12 // Filter bbn.fn.sum(invited, "attendees", {confirmed: true}); // 7 ```

Example

```javascript let cart = [ {article: "Toothpaste", price: 2.50, quantity: 1}, {article: "Toothbrush", price: 6, quantity: 2}, {article: "Banana", price: 0.50, quantity: 3}, {article: "T-shirt", price: 14, quantity: 3} ]; bbn.fn.sum(cart, a => a.price * a.quantity); // 58 // Only the items with a quantity equal to 3 bbn.fn.sum(cart, a => a.price * a.quantity, {quantity: 3}); // 43.5 ```

Returns the sum of the given property or function for the array's elements matching the filter. - The filtering arguments follow the same scheme as bbn.fn.search. BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way

This website uses cookies to ensure you get the best experience on our website.