lodash 去除空值

pickBy 方法接受一个对象和一个断言函数,并返回一个新对象,其中只包含满足断言函数条件的键值对。

下面是使用 pickBy 方法去除对象中的空值的示例代码:

const _ = require('lodash');

const obj = {
  name: 'Alice',
  age: 30,
  address: null,
  phone: undefined,
};

const filteredObj = _.pickBy(obj, _.identity);
console.log(filteredObj);

.

posted @ 2022-08-16 20:57  每天都要进步一点点  阅读(511)  评论(0)    收藏  举报