merge-collections
v1.0.0
Published
Merge collections (objects) by key value. Somewhat similar to SQL join.
Downloads
7
Maintainers
Readme
Install
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