过滤掉具有空值的数组,下划线 [英] Filter out an array with null values, underscore

查看:100
本文介绍了过滤掉具有空值的数组,下划线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个数组:

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

我想删除空值。使用下划线有一种简单的方法吗?

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

推荐答案

尝试使用 _。不带(数组,*值)它将删除您不需要的所有值。在你的情况下* values == null

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

这篇关于过滤掉具有空值的数组,下划线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆