I have a JS object like this:
const myObj = {
'$prop1': 1,
'$prop2': 2,
'$prop3': 3
};
and an array of object like this:
const myArray = [
{
prop1: 'some stuff',
prop2: 'some other stuff',
propKey: '$prop1'
},
{
prop1: 'some stuff',
prop2: 'some other stuff',
propKey: '$prop2'
},
{
prop1: 'some stuff',
prop2: 'some other stuff',
propKey: '$prop5'
},
];
I am trying to write a function fo filter myObj and only get the fields I can find in myArray.propKey.
this is what I tried so far with no luck:
export const filterVariantContentByColumns = (myObj, myArray) => {
const objArray = Object.keys(myObj).map(i => myObj[i]);
return objArray.filter(value => myArray.includes(value.key_name));
console.log(res);
};
any idea how to do that please?