I've been racking my brain trying to find a more efficient way to achieve this without upsetting my eslint settings. Essentially, I'm attempting to remove keys from an object that do not exist in an array of objects. The code I currently have works fine but triggers eslint errors:
fieldData = recipeOutputFields(z, bundle);
return promise.then((response) => response.json.response.map((item) => {
const temp = item;
temp.id = temp.customer_id;
const diff = {};
for (const [key, value] of Object.entries(temp)) {
fieldData.some((el, val) => {
if (el.key === key) {
diff[key] = value;
}
});
}
Here are some examples of the data I'm dealing with:
let theObjectINeedToRemoveKeysFrom = {
key1: "test",
key2: "test2",
key3: "test",
key4: "test",
}
let theArrayOfObjectsToFilterBy = [
{
key: "key1",
type: "string",
},
{
key: "key2",
type: "string",
},
{
key: "key4",
type: "int",
},
]
The desired output would be:
let expectedResult = {
key1: "test",
key2: "test2",
key4: "test",
}
Any ideas on how to simplify my function to comply with eslint rules?
The ES Lint Errors: https://i.sstatic.net/6X9L2.png