📜  从对象打字稿代码示例中修剪未定义的键

📅  最后修改于: 2022-03-11 14:48:20.430000             🧑  作者: Mango

代码示例2
const obj = {
  a: 1,
  b: undefined
}

// pure functional approach without side-effects
const newObject = Object.keys(obj).reduce((acc, key) => {
  const _acc = acc;
  if (obj[key] !== undefined) _acc[key] = obj[key];
  return _acc;
}, {})

console.log(newObject)
// Object {a: 1}