Skip to content
On this page

sumBy

Add up the given array of numbers, using the given function or key.

Example

const users = [
  { age: 1, name: 'user1' },
  { age: 2, name: 'user2' },
  { age: 3, name: 'user3' },
]
sumBy(users, (user) => user.age) // => 6
sumBy(users, 'age') // => 6

Playground

const { sumBy } = require('rhodash')
const users = [
  { age: 1, name: 'user1' },
  { age: 2, name: 'user2' },
  { age: 3, name: 'user3' },
]
sumBy(users, user => user.age) // => 6