I have an object that looks like this:
var myObject = { a: { b: [{}], c: [{}, {d: 2}], e: 2, f: {} }, g:{}, h:[], i: [null, 2] }
I want to remove null values and and empty objects (array and objects) so that it looks like:
{ a: {c: [ {d: 2} ], e: 2 }, i: [ 2 ] }
The function should remove null values, empty objects and empty arrays. Any elegant way to do it ?
a.cas an array, why isn't the non-empty array preserved, that is,{ a: { c: [{ d: 2 }], e: 2}, i: [2] }? Why does theiarray of[null, 2]disappear and then appear cleaned as a property ofg? Why are there twocproperties in the output (nested), whereas there's only ever onecproperty in the input?{ a: { c: [{ d: 2 }], e: 2}, i: [2] }, as expected from the problem description, so I'm assuming that the desired output posted in the question just has typos?