https://github.com/jakecyr/subtotal-object-array
Subtotal JavaScript object array by change in column
https://github.com/jakecyr/subtotal-object-array
algorithm angularjs javascript sub-total
Last synced: about 2 months ago
JSON representation
Subtotal JavaScript object array by change in column
- Host: GitHub
- URL: https://github.com/jakecyr/subtotal-object-array
- Owner: jakecyr
- Created: 2018-07-12T19:36:32.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-01-28T03:09:30.000Z (almost 6 years ago)
- Last Synced: 2025-03-09T15:57:21.792Z (9 months ago)
- Topics: algorithm, angularjs, javascript, sub-total
- Language: JavaScript
- Size: 5.86 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Subtotal JavaScript Object Array
Subtotal JavaScript object array by change in a specified key. Originally made for an AngularJS subtotals HTML table.
### Example Usage
The following code:
```javascript
const subtotal = require('../src/subtotal');
const masterData = [
{
name: 'Jake',
value_0: 1,
value_1: 2
}, {
name: 'John',
value_0: 4,
value_1: 2
}, {
name: 'John',
value_0: 4,
value_1: 1
}, {
name: 'Sally',
value_0: 8,
value_1: 2
}
];
let output = subtotal(masterData, 'name', ['value_0', 'value_1']);
```
will produce the following JavaScript object:
```javascript
{
"John":{
data: [{name: "John", value_0: 4, value_1: 2}, {name: "John", value_0: 4, value_1: 1}],
totals:{
value_0: 8,
value_1: 3
}
},
...
}
```