Is there a convenient way to filter bigObject with only the properties defined in filterInterface to get filteredObject as output?
The big object has a lot of properties and I want to strip the information down to the properties I need (to save it somewhere, don’t want to/can’t save the complete object).
I prepared the following code as a jsfiddle here.
// My big object
var bigObject = {
prop1: {
prop2: {
prop3: 123,
prop4: 456,
prop5: "TEST"
},
prop6: 789,
prop7: "xxx"
},
prop8: 5.6,
prop9: 3
};
// My "interface" to filter the object
var filterInterface = {
prop1: {
prop2: {
prop3: true,
},
prop7: true
}
};
// My expected result, only the properties of
// big Object which match the interface
var filteredObject = {
prop1: {
prop2: {
prop3: 123,
},
prop7: "xxx"
}
};
Briefly, I’d expect something like:
Include recursion if you want “deep” filtering: