How to Compare Two Objects and Get Key-Value Pairs of Their Differences

compare two objects and return true if part of the object key value pair exists

You can use every() on the array produced by Object.entries() to test if every key/value pair in the expected matches the actual:

const expectedValue = {   city: "San Jose",   state: "california",   zip: "95234"}
const actualObject = { address: "5543322 Adam St", city: "San Jose", state: "california", zip: "95234", country: "USA"}

let test = Object.entries(expectedValue) .every(([key, value]) => actualObject[key] === value )
console.log(test)

How to compare two different Object keys and update it's value if keys are same in Javascript?

You can do this by using the spread syntax.

Just spread the old object first followed by the new object.

Matching keys if any would be updated by the values from the new object and new keys in the new object would be added:

let oldObject = {name:"Dhanush",age:24,sex:"Male",education:"Btech"}
let newObject = {name:"Dhanush kumar S",age:23,sex:"Male"}

const merge = (oldObj, newObj) => {
return {...oldObj, ...newObj};
}
console.log(merge(oldObject, newObject));

javascript compare value of a certain key in all objects

Get the value of the first element, then use every to compare it to other values.every will return false on the first non-match. There is no need to check every element in the array after you found ONE that doesn't match.

 let list =[    { name: 'foo', country: 'Foos' },    { name: 'bar', country: 'Foos' },    { name: 'baz', country: 'Foos' }];

function isCountryTheSameInAllObjects(list) { if (!(list && list.length)) return true; // If there is no list, or if it is empty, they are all the same, aren't they? let compare = list[0].country; return list.every( item => item.country === compare);}
console.log('is Country same?', isCountryTheSameInAllObjects(list));

Comparing two similar objects (holding same keys) and returning key value pairs that are different

Loop through one object, then compare its values with the corresponding element of the other.

const initialValues= { name: "Robert Terrell", email: "billy@gmail.com" };
const formData = { name: 'New Name', email: 'new email' };

for (const [key, value] of Object.entries(initialValues)) {
if (value != formData[key]) {
console.log(`${key}: ${value} != ${formData[key]}`);
}
}

Compare two objects and get common values JavaScript

Here is a simple example that uses a combination of Object.values and Object.keys as arrays that are filtered to produce your prescribed output:

let obj1 = { "val1":"test", "stream":{ "iscommisonAccount":false, "istradeAccount":true } }; 
let obj2 = { "val1":"test", "stream":{ "iscommisonAccount":true, "istradeAccount":true } };


let obj3 = { "val1":"test", "stream":{ "iscommisonAccount":true, "istradeAccount":true } };
let obj4 = { "val1":"test", "stream":{ "iscommisonAccount":false, "istradeAccount":true } };

let obj5 = { "val1":"test", "stream":{ "iscommisonAccount":false, "istradeAccount":false } };
let obj6 = { "val1":"test", "stream":{ "iscommisonAccount":false, "istradeAccount":false } };

let obj7 = { "val1":"test", "stream":{ "iscommisonAccount":true, "istradeAccount":false } };
let obj8 = { "val1":"test", "stream":{ "iscommisonAccount":true, "istradeAccount":false } };

interface Data {stream:{[key: string]: boolean}};

function objFilter(objA: Data, objB: Data): Data {
let out: Data = {stream:{}};
Object.keys(objA.stream).filter((value, idx) =>
Object.values(objA.stream)[idx] === Object.values(objB.stream)[idx] ?
out.stream[value] = Object.values(objA.stream)[idx] :
false
);
return out;
}
console.log(objFilter(obj1, obj2)); //istradeAccount
console.log(objFilter(obj3, obj4)); //istradeAccount
console.log(objFilter(obj5, obj6)); //iscommisonAccount && istradeAccount
console.log(objFilter(obj7, obj8)); //iscommisonAccount && istradeAccount
console.log(objFilter(obj2, obj7)); //iscommisonAccount

Comparing certain key, value pairs within an object - No Direct Matches (JavaScript)

First. Let's separate our sellers from the buyers by filtering each group.

var data = [{...}] // assume is the long list of data you posted
var buyers = data.filter(function(item) {return item.type === 'Buyer'});
var sellers = data.filter(function(item) {return item.type === 'Seller'});

Now we have 2 arrays buyers and sellers. We can now iterate the buyers and search for matching sellers

buyers.forEach(function(buyer) {
sellers.forEach(function(seller) {
// Here we can compare our buyers and sellers.
// For each buyer we'll iterate over all the sellers and look for a match.
if (buyer.price >= seller.price) {
// You've found a match! now do something with it.
// Of course here we are comparing only price, you may want to compare
// multiple keys, like if it's the same product.
}
})
})

How to compare elements in an object and return the higher value? *Javascript*

On each iteration check if the current or previous key value is the largest, and store. Store the largest in the largest variable. In the end return the largest variable, and it's value (object[largest]):