merge-collections

1.0.0 • Public • Published

Install Build Status

Merge collections (objects) by key value. Somewhat similar to SQL join.

$ npm install merge-collections --save

Usage

var mergeCollections = require('merge-collections');
 
var coll1 = [{
    id: 1,
    name: 'John'
}, {
    id: 2,
    name: 'Mary'
}];
 
var coll2 = [{
    id: 1,
    lastName: 'Smith'
}, {
    id: 2,
    lastName: 'Jane'
}];
 
mergeCollections(coll1, coll2, 'id');
//=> [{ id: 1, name: 'John', lastname: 'Smith' }, { id: 2, name: 'Mary', lastname: 'Jane' }];

Important

In the above example, the second collection (coll2) will overwrite the values of first collection (coll1) that share the same property.

License

MIT © Dennis Jin

Package Sidebar

Install

npm i merge-collections

Weekly Downloads

1

Version

1.0.0

License

MIT

Last publish

Collaborators

  • desuvader