Per Ström Per Ström - 5 months ago 19
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

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

http://underscorejs.org/#without