How to delete null object inside another object in javascript

I have an javascript object which contains another few objects.
For example,

[{id : ’11’}, null, null, {id : ’12’}, {id : ’13’}, {id : ’13}]

Here I want to delete the null objects from this object.
I have tried to loop through the object and tried to delete the object where it is null.
But it is not traversing through the empty elements.

//Delete NULL elements
for (var key in objData) {
    if(objData[key].length === 0){
        delete objData[key];
    }
    if (objData[key] == null || objData[key] == undefined) {
        delete objData[key];
    }
}

What am I missing here ?
The object is not even traversing through the null elements.

9 thoughts on “How to delete null object inside another object in javascript”

Leave a Comment