I want to remove all keys that have values of N/A, - or an empty string. If one of these values appear in the array the I want to remove that single item from the array. So for instance my example output is this:
{"name":{"first":"Daniel","middle":"N/A","last":"Smith"},"age":45}
The output I expect is this
{"name":{"first":"Daniel","last":"Smith"},"age":45}
I have tried this but it does not seem to work:
function recurse(resp) {
let data;
for (var x in resp) {
data = resp[x]
if (data === 'null' || data === null || data === '-' || typeof data === 'undefined' || (data instanceof Object && Object.keys(data).length == 0)) {
delete resp[x];
}
if (data instanceof Object) {
data = recurse(data);
}
}
return resp;
}