AdamSulc
AdamSulc

Reputation: 450

Check if any property of object has null value

I have following array of objects data, that has multiple properties, some of them can have null value.

enter image description here

I want to filter through this array of objects and remove every object that has property of null value. So far I have tried this code, but with no luck:

const noNull = data.filter((doc) => { return Object.values(doc).some(prop => { if (prop !== null) return doc; } )});

Any ideas how can I achieve this?

Thank you in advance.

Upvotes: 2

Views: 920

Answers (1)

Biswa Soren
Biswa Soren

Reputation: 325

Here Updated to keep items which do not have a null value

const noNull = obj.filter((doc) => { return Object.values(doc).every(prop => prop !== null)})

.some() and .every() expect boolean return value

reference

Upvotes: 3

Related Questions