Just to build a good answer on top of @Nenad Vracar, you could use an object instead of Array with includes for a quick search:
const acceptedValues = ["value1", "value3"]; const myObject = { prop1: "value1", prop2: "value2", prop3: "value3" }; const lookup = acceptedValues.reduce( (memo, prop) => { memo[prop] = true; return memo; }); const filteredObject = Object.keys(myObject).reduce((filtered, key) => { if(lookup[myObject[key]]){ filtered[key] = myObject[key]; } return filtered; }, {}); console.log(filteredObject);
Also, that includes does not do this work, but I decided to provide an alternative view.
source share