$.array.calculate
Calculate method of array helpers
$.array.calculate(fromArray, newProperty, callbackFunction)
// Example:
const fromArray = [
{ name: 'Item-1', quantity: 6, price: 12, total: 0 },
{ name: 'Item-2', quantity: 5, price: 7.5, total: 0 },
{ name: 'Item-3', quantity: 3, price: 4 },
{ name: 'Item-4', quantity: 7, price: 9.6 }
]
$.array.calculate(fromArray, 'total', (quantity, price) => {
return Number(quantity) * Number(price)
})
//=> [
// { name: 'Item-1', quantity: 6, price: 12, total: 72 },
// { name: 'Item-2', quantity: 5, price: 7.5, total: 37.5 },
// { name: 'Item-3', quantity: 3, price: 4, total: 12 },
// { name: 'Item-4', quantity: 7, price: 9.6, total: 67.2 }
//]Last updated