I am trying to filter the keys of objects which are empty(i,e with value ”) and if there is nested object with keys empty that should also get filtered. The method i am using is filtering keys at parent level but not in nested objects
input
obje = {
a:'a',
b:'',
c:'c',
d: {
e:'e',
f:'',
g:'',
h:''
}
}
output
obje = {
a:'a',
c:'c',
d: {
e:'e',
}
}
filterKeys(obj: any) {
return Object.fromEntries(
Object.entries(obj).filter(([key, value]) => {
return typeof value !== 'object'
? value !== ''
: this.filterKeys(obj[key]);
}),
);
}
with the above method i am getting output
obje = {
a:'a',
c:'c',
d: {
e:'e',
f:'',
g:'',
h:''
}
}
not sure why it is not filtering inside nested object