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' }