Filter out an array with null values, underscore

前端 未结 5 1422
醉话见心
醉话见心 2021-02-11 18:32

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 unders

5条回答
  •  走了就别回头了
    2021-02-11 18:41

    This will work for you

    Filter

    _.filter(arr,function (value) {
        return value!==null;
    })
    

    Reject

    _.reject(arr,function (value) {
        return value===null;
    })
    

提交回复
热议问题