I want to filter out key value pairs which are common in both objects. There are two objects:
first = {a:3 , b:4}
second = {a:5 , b:4}
I used the below code to solve this:
c = {}
for (const key of Object.keys(first)) {
for( const k of Object.keys(second)){
if ( key == k){
if (first[key]==second[k]){
c[key] = first[key]
}
}
}
}
This works fine and gives me the output {b:4}, but for the below test input values I get empty object as the output, I am not sure how to check for values that are common but not equal.
first = {a: 3, b: {x:7}};
second = {a: 4, b: {x: 7, y: 10}}
Here the output should be:
{b: {x:7}}