vue如何将对象中属性值为“”,null,undefined的属性去掉,组成一个新对象

function removeEmptyProperties(obj) {  
  const newObj = {};  
  for (const key in obj) {  
    if (obj.hasOwnProperty(key) && obj[key] !== undefined && obj[key] !== null) {  
      newObj[key] = obj[key];  
    }  
  }  
  return newObj;  
}  
  
const originalObject = {  

  type: "book",

  user: "Alice",

  storeName: undefined,

  storeId: undefined,

  storeData: "",

  storeDataId: null,
};  

const objectWithoutEmptyProperties = removeEmptyProperties(originalObject);  
console.log(objectWithoutEmptyProperties);

// 输出: { type: 'book', user: 'Alice', tenantId: '123' }
 

上一篇:04-JavaScript函数


下一篇:Vue element-plus 导航栏 [el-menu]