What is the best way to filter an object this way in ES6?
Starting data:
const acceptedValues = [\"value1\",\"value3\"]
const myObject = {
prop1:
Why not a simple for loop?
const acceptedValues = ["value1","value3"]
const myObject = {
prop1:"value1",
prop2:"value2",
prop3:"value3"
};
var filteredObject = {};
for(e in myObject) {
if (myObject.hasOwnProperty(e)) {
if (acceptedValues.indexOf(myObject[e]) != -1) {
filteredObject[e] = myObject[e];
}
}
}
console.log(filteredObject);