README
arr-merge
Merges primitive and object arrays, optionally grouped by key.
Installation
npm install arr-merge
Usage
Simple arrays
var merge = require('arr-merge');
var arrayA = ['a', 1],
arrayB = ['b', 1];
var mergedArray = merge(arrayA, arrayB);
Result
['a', 1, 'b', 1]
Object arrays
var arrayA = [{ a: '1' }],
arrayB = [{ b: '1' }];
var mergedArray = merge(arrayA, arrayB);
Result
[{ a: '1' }, { b: '1' }]
Object arrays grouped by key
var arrayA = [
{ a: '1' },
{ a: '2' },
{ a: '3' }
];
var arrayB = [
{ a: '1', b: '1' },
{ a: '2', b: '2' },
{ a: '4' }
];
var mergedArray = merge(arrayA, arrayB, 'a');
Result
[
{ a: '1', b: '1' },
{ a: '2', b: '2' },
{ a: '3' },
{ a: '4' }
]
Tests
npm test