...but with objects.
for example :
one = {a: false, c: false, e: false};
two = {a: true, b: false, c: false, d:false};
result = somethingJavascriptHas.ObjectAnd(one, two);
console.log(result);
would return :
{a: false, c: false};
(I'm interested in the key, not the rest, so I discard the second object's value in favor of the first's here. In my case the two object's values will always be the same simply some of their entries will be missing or not and I want a final object that includes only key's (with the first object key's value) that are present in both objects)
is this possible?
For completeness' sake OR, XOR and NOT. (again assume priority of values for the first passed object)
You could use the Array#reduce
function on one of your objects keys and check if the properties of both objects are not undefined :
var one = {a: false, c: false, e: false};
var two = {a: true, b: false, c: false, d:false};
var three = Object.keys(one).reduce((acc, curr) => {
if(two[curr] !== undefined){
acc[curr] = one[curr] && two[curr];
}
return acc;
}, {});
console.log(three);