Per Ström Per Ström - 1 year ago 111
Javascript Question

Filter out an array with null values, underscore

I have this array:

[null, {name:'John'}, null, {name:'Jane'}]

I want to remove the null values. Is there an easy way to do this with underscore?

Answer Source

Try using _.without(array, *values) it will remove all the values that you don't need. In your case *values == null

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download