Returns a total sum of specific key of an array of objects
- Quick start
Add reduce-sum to your project using npm or yarn.
Install (NPM):
$ npm install reduce-sum --save
Install (Yarn):
$ yarn add reduce-sum
Import ReduceSum into Your Project
import ReduceSum from 'reduce-sum'
Use ReduceSum
ReduceSum([{ a: 139, c: 22 }, { a: 233, b: 'hi' }, { a: 112, b: 18 }], 'a')
// 484
let cart = [{ name: 'Jeans', quantity: 1 }, { name: 'Socks', quantity: 3 }, { name: 'T-Shirt', quantity: 6 }]
let totalItems = reduceSum(cart, 'quantity')
// 10
Pull requests for new features, bug fixes, and suggestions are welcome!