I got 2 Json arrays with some common field. But they are not sorted in any specific order. I want to be able to merge them based on a property.
var merge = require('deepmerge');
var one = [{
id:1
},
{
id:2
}];
var two = [{
id:2,
name:"test1"
},
{
id:1,
name:"test2"
}];
console.log(merge(one,two));
deepmerge results in blind merge, first element with first element from the other array.
[ { id: 2, name: 'test1' }, { id: 1, name: 'test2' } ]
I know its possible to manually iterate thru one array, find the matching node from the other array and merge them...wondering if there is any library to do this. Thoughts?