1.0.0 • Published 10 years ago
merge-collections v1.0.0
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
1.0.0
10 years ago