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).
const objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }]
sumBy(objects, ({ n }) => n)
// => 20
| Name | Type | Attribute | Description |
|---|---|---|---|
| array | The array to iterate over. | ||
| iteratee | The iteratee invoked per element. |
{
"comment": "/**\r\n * This method is like `sum` except that it accepts `iteratee` which is\r\n * invoked for each element in `array` to generate the value to be summed.\r\n * The iteratee is invoked with one argument: (value).\r\n *\r\n * @since 4.0.0\r\n * @category Math\r\n * @param {Array} array The array to iterate over.\r\n * @param {Function} iteratee The iteratee invoked per element.\r\n * @returns {number} Returns the sum.\r\n * @example\r\n *\r\n * const objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }]\r\n *\r\n * sumBy(objects, ({ n }) => n)\r\n * // => 20\r\n */",
"meta": {
"range": [
595,
714
],
"filename": "sumBy.js",
"lineno": 20,
"path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo",
"code": {
"id": "astnode100008898",
"name": "sumBy",
"type": "FunctionDeclaration",
"paramnames": [
"array",
"iteratee"
]
}
},
"description": "This method is like `sum` except that it accepts `iteratee` which is\rinvoked for each element in `array` to generate the value to be summed.\rThe iteratee is invoked with one argument: (value).",
"since": "4.0.0",
"tags": [
{
"originalTitle": "category",
"title": "category",
"text": "Math",
"value": "Math"
}
],
"params": [
{
"type": {
"names": [
"Array"
]
},
"description": "The array to iterate over.",
"name": "array"
},
{
"type": {
"names": [
"function"
]
},
"description": "The iteratee invoked per element.",
"name": "iteratee"
}
],
"returns": [
{
"type": {
"names": [
"number"
]
},
"description": "Returns the sum."
}
],
"examples": [
"const objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }]\r\rsumBy(objects, ({ n }) => n)\r// => 20"
],
"name": "sumBy",
"longname": "sumBy",
"kind": "function",
"scope": "global",
"___id": "T000002R000809",
"___s": true,
"filepath": "sumBy.js"
}