# @writetome51/get-sum-from-property

> Gets values of a particular property found in each object in array of objects, and returns their sum

Latest version **2.0.0** (published 2020-08-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install @writetome51/get-sum-from-property
pnpm add @writetome51/get-sum-from-property
yarn add @writetome51/get-sum-from-property
bun add @writetome51/get-sum-from-property
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2020-08-04 |
| First published | 2019-02-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 4.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Steve Thompson |
| Maintainers | writetome51 |
| Keywords | get, sum, value, property, objects |

## Links

- npm: https://www.npmjs.com/package/@writetome51/get-sum-from-property
- Repository: https://github.com/writetome51/get-sum-from-property
- Homepage: https://github.com/writetome51/get-sum-from-property#readme
- Issues: https://github.com/writetome51/get-sum-from-property/issues
- npm.io page: https://npm.io/package/@writetome51/get-sum-from-property

## Dependencies (2)

- [@writetome51/get-array-from-property](https://npm.io/package/@writetome51/get-array-from-property.md) ^2.0.0
- [@writetome51/get-sum-average-product](https://npm.io/package/@writetome51/get-sum-average-product.md) ^2.0.0

## Recent versions

- 2.0.0 (latest) — 2020-08-04
- 1.0.1 — 2019-03-04
- 1.0.0 — 2019-02-07

## README

# getSumFromProperty(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;property: string,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;objects: object[]<br>): number

Returns sum of `property` found in each of `objects`.   
Value of `property` in each object must be type 'number'.  
The parameter `property` is a string that can include dot notation  
( i.e,  `'property.subproperty.subsubproperty'` ) .  

Note:  `property` does not have to be an object key. It can also be an array index.  
If you are referring to an array index, here you need to use dot-notation  
and not square braces.  Example: `'1.0' instead of [1][0]`

## Examples
```js
let players = [
	{name: 'Bill Mill', strikeouts: 10},
	{name: 'Milly Buttons', strikeouts: 12},
	{name: 'Mick Stan', strikeouts: 5},
	{name: 'Kelly Rogers', strikeouts: 2},
	{name: 'Angus Beef', strikeouts: 11},
	{name: 'Charlie Soup', strikeouts: 10}
];
getSumFromProperty('strikeouts', players);
    // --> 50


players = [
	{stats: {strikeouts: 100}},
	{stats: {strikeouts: 20}},
	{stats: {strikeouts: 30}},
	{stats: {strikeouts: 40}},
	{stats: {strikeouts: 10}},
	{stats: {strikeouts: 15}}
];
getSumFromProperty('stats.strikeouts', players);
    // --> 215


let numberGroups = [
	[[1, 5], [6, 10]],
	[[11, 15], [16, 20]],
	[[21, 25], [26, 30]],
	[[31, 35], [36, 40]]
];
// get the sum of [1,11,21,31]
getSumFromProperty('0.0', numberGroups);
    // --> 64


players = [
	{name: 'Bill Mill', strikeouts: '10'}, // string will trigger error.
	{name: 'Milly Buttons', strikeouts: 12},
	{name: 'Mick Stan', strikeouts: 5},
	{name: 'Kelly Rogers', strikeouts: 2}
];
getSumFromProperty('strikeouts', players);
// console: "Error: Input must be a finite number of type 'number'"


players = [
	{name: 'Kelly Rogers', strikeouts: 2},
	{name: 'Angus Beef', strikeouts: 11},
	{name: 'Charlie Soup', strikeouts: 10},
	{name: 'Willy'}  // missing property will trigger error.
];
getSumFromProperty('strikeouts', players);
// console: "Error: Input must be a finite number of type 'number'"
// (In this case, the input that is not a number is undefined)
```

## Installation
```bash
npm i @writetome51/get-sum-from-property
```

## Loading
```js
import {getSumFromProperty} from '@writetome51/get-sum-from-property';
```

---
_Source: https://npm.io/package/@writetome51/get-sum-from-property · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
