I want to remove unnecessary key values pairs in a user object based on an array, essentially a whitelist. I have looked at reduce(), filter() and map() but can't quite get the implementation to work.
Here is my code currently
const user = {
"email": "[email protected]"
"name": "Bob"
"surname": "Smith"
};
const userFields = [`email`, `name`]; // array of whitelist
Before I iterate through the object properties, I'd like to reduce Object to have fields only in the array whitelist, so our man Bob Smith would end up like this
const user = {
"email": "[email protected]"
"name": "Bob"
};
Thanks!