嗨,我目前遇到了检查具有另一个嵌套对象的对象的问题,如果其中的所有值都是 null 或 0
我的对象如下:
{
"city":0,
"road":{
"max":null,
"min":null
},
"size":{
"max":null,
"min":null
},
"type":null,
"ward":0,
"floor":null,
"price":{
"max":null,
"min":null
},
"street":0,
"toilet":null,
"balcony":null,
"bedroom":null,
"district":0,
"frontend":{
"max":null,
"min":null
},
"direction":null,
"living_room":null
}
我需要检查其中的每个值是 0 还是 null,如果所有值都是 0或 null,则返回true ,如果任何值不同于 null 或 0 ,则返回false
我不能使用:
Object.values(object).every(i => (i === null || i === ''))
它返回 False 因为嵌套对象仍然认为是不同于 0 和 null 的值
如果条件一次检查它的每一个值,我不想写超长
无论如何要遍历对象并检查它的嵌套对象吗?