var firstObject = { x: 0, y: 1, z: 2, a: 10, b: 20, e: 30 },
secondObject = { x: 0, y: 1, z: 2, a: 10, c: 20, d: 30 };
function intersection(o1, o2) {
return Object.keys(o1).filter({}.hasOwnProperty.bind(o2));
}
document.write('<pre>' + JSON.stringify(intersection(firstObject, secondObject), 0, 4) + '</pre>');
Run code snippet
let data = [
{
id: "1",
name: "test"
},
{
id: "2",
name: "test"
}
];
let data2 = [
{
id: "1",
name: "test"
},
{
id: "3",
name: "test"
}
];
const result = data.filter((a) => data2.some((b) => a.id === b.id));
console.log(result);