js 删除对象中所有值为null的属性

let obj={
    'a':'a',
    'b':null,
    'c':'c'
}

var removePropertyOfNull=function(obj){
    Object.keys(obj).forEach(item=>{
        if(!obj[item])  delete obj[item]
    })
    return obj;
}
removePropertyOfNull(obj) //obj={'a':'a','b':'b'}

猜你喜欢

转载自www.cnblogs.com/xingguozhiming/p/10463283.html