Skip to content

jakecyr/subtotal-object-array

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

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:

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:

{
  "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
    }
  },
  ...
}

About

Subtotal JavaScript object array by change in column

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published