写一个js方法两个对象求交集

37 阅读1分钟

"```javascript function findIntersection(obj1, obj2) { let result = {}; for (let key in obj1) { if (key in obj2 && obj1[key] === obj2[key]) { result[key] = obj1[key]; } } return result; }

const obj1 = { a: 1, b: 2, c: 3 }; const obj2 = { b: 2, c: 3, d: 4 };

const intersection = findIntersection(obj1, obj2); console.log(intersection); // Output: { b: 2, c: 3 }