📌  相关文章
📜  javascript 删除空对象项 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:39.709000             🧑  作者: Mango

代码示例1
var test = {
  test1: null,
  test2: 'somestring',
  test3: 3,
}

function clean(obj) {
  for (var propName in obj) {
    if (obj[propName] === null || obj[propName] === undefined) {
      delete obj[propName];
    }
  }
  return obj
}

console.log(test);
console.log(clean(test));