js删除对象上值无效的属性
function clearObject(obj) {
for (const key in obj) {
if (typeof obj[key] != 'number' && !obj[key]) {
delete obj[key]
}
}
return obj
}
let obj = clearObject({
name: '',
age: 1,
status: 0,
created_at: undefined,
sex: null
})
// { age: 1, status: 0 }