Determine whether other key-value pairs in the object except Boolean values are empty?


let joke ={
    a:"1",
    b:"2",
    c:false
}
for(let key in joke){
    if(joke[key]==""){
        alert("")
    }
}

as above, in the loop check, c is a Boolean value false, judgment pops up alert, ask how to ignore the case that the key-value pair is a Boolean value, and only detect whether the string and number types are empty?

Mar.12,2021

for(let key in joke){
    if(joke[key] === '' && typeof joke[key] !== 'boolean'){
        alert('')
    }
}

use =
joke [key] ='
if the check value is null or undefined , you can list these conditions
joke [key] =''| joke [key] = null | | joke [key] = undefined

< hr class= "answer".

= implicit type conversion has occurred. If you change it to = , it must be ' to enter.

only detects whether the string and numeric types are empty

does not understand this sentence, do you want the number 0 to also determine a null value?

Menu