_ filter in lodash to match 2 json arrays code example
Example 1: javascript compare object arrays keep only entries not in both
var result = result1.filter(function (o1) {
return result2.some(function (o2) {
return o1.id === o2.id; // return the ones with equal id
});
});
// if you want to be more clever to find those in common:
let result = result1.filter(o1 => result2.some(o2 => o1.id === o2.id));
// To find those in 1 NOT in 2:
let result = result1.filter(o1 => !result2.some(o2 => o1.id === o2.id));
Example 2: get lodash
var object = { 'a': [{ 'b': { 'c': 3 } }] }; _.get(object, 'a[0].b.c');// => 3 _.get(object, ['a', '0', 'b', 'c']);// => 3 _.get(object, 'a.b.c', 'default');// => 'default'