<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
function isFalsy (value) {
return value === 0 ? false : !value
} ;
function cleanObject (object) {
const temp = { ...object };
Object.keys(temp).forEach((key) => {
console.log(temp[key],"temp[key]")
const value = temp[key];
if (isFalsy(value)) {
delete temp[key];
}
});
return temp;
};
console.log(cleanObject({name:"geyao",age:0,sex:"男",happy:undefined,hh:"",gg:NaN,gua:"计算机"}))
</script>
</body>
</html>