Fork me on GitHub

去掉对象中值为null和undefined的空字段

const v1 = {
  a: '1',
  b: 20,
  c: null,
  d: undefined,
  }

const v1 = {
  a: '1',
  b: 20,
  }



const params = Object.keys(data) .filter((key) => data[key] !== null && data[key] !== undefined) .reduce((acc, key) => ({ ...acc, [key]: data[key] }), {});

 

https://www.jianshu.com/p/4d76644b0e42

posted @ 2022-08-23 00:03  让梓航飞  阅读(31)  评论(0)    收藏  举报