Reputation: 450
I have following array of objects data
, that has multiple properties, some of them can have null value.
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
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
Upvotes: 3