Count array except the empty values

I have an array of objects like this:

 var a = [{'id': 1}, {'id':''}, {'id':3}]

And now I need to count the array except the empty id so the answer should be 2.
I tried to used filter function but I couldn’t get my expected out put.

This is the codes I am done so far.

         a.filter(Boolean).length; // Returns 3. It should be 2.

Any idea is much appreciated. Thank you

16 thoughts on “Count array except the empty values”

Leave a Comment