Using JavaScript/Node I'm trying to have a function check if a string (x) is in any one of the objects in an array. Here is an example:
{
x: 'testx',
y: 'testy',
z: 'textz'
},
{
a: 'testa',
b: 'testb',
c: 'textc'
}
]
var arr2 = [
{
x: 'testx'
},
{
a: 'testa',
b: 'notb'
}
]
I want to see check if any of arr2's properties are inside of any of the properties within the arr 1 objects, and simply log to the console if a property isn't the same. Sorrry if this is confusing, I'm new to JavaScript and it's hard to explain :(
I've tried this:
newProducts.each((i, el) => {
if (Object.values(arr).indexOf('testb') > -1) {
console.log(`has testb`);
}
});
I've also tried looping over both arrays and comparing, but I can't pick out the ones that are different.
arr1andarr2? Likex: 'testx'should be checked only onarr[0]?