@nodejavascript/array-key-sum
0.1.0 • Public • Published Install
npm i @nodejavascript/array-key-sum
Usage
import arrayKeySum from '@nodejavascript/array-key-sum'
const sampleArray = [
{
id: 1,
name: 'Foo',
cost: 4.50
},
{
id: 2,
name: 'Bar',
cost: 4.50
},
{
id: 3,
name: 'Bar',
cost: 3.50
}
]
const sumOfCost = arrayKeySum(sampleArray, 'cost')
// sumOfCost => 12.5
const sumOfCostFoo = arrayKeySum(sampleArray.filter(i => i.name === 'Foo'), 'cost')
const sumOfCostBar = arrayKeySum(sampleArray.filter(i => i.name === 'Bar'), 'cost')
// sumOfCostFoo => 4.5
// sumOfCostBar => 8
Package Sidebar
Install
npm i @nodejavascript/array-key-sum
Weekly Downloads