Merge collections (objects) by key value. Somewhat similar to SQL join.
$ npm install merge-collections --save
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' }];
In the above example, the second collection (coll2
) will overwrite the values of first collection (coll1
) that share the same property.
MIT © Dennis Jin