This method is like sum except that it accepts iteratee which is invoked for each element in array to generate the value to be summed. The iteratee is invoked with one argument: (value).
sum
iteratee
array
5.6.0
const objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }]sumBy(objects, ({ n }) => n)// => 20 Copy
const objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }]sumBy(objects, ({ n }) => n)// => 20
The array to iterate over.
The iteratee invoked per element.
Returns the sum.
This method is like
sum
except that it acceptsiteratee
which is invoked for each element inarray
to generate the value to be summed. The iteratee is invoked with one argument: (value).Since
5.6.0
Example