mercredi 12 septembre 2018

javascript: build an if statement from filled in object properties, excluding blank ones

Novice coder here. I have an object like this

object = {
     attribute1:'red',
     attribute2:'green',
     attribute3:''
}

lets say the attributes can be any color, or an empty string ''. I want to make an if statement to search through divs, but I want to build the if statement from the filled in values, not the empty ones, so like

if(object.attribute1 === 'red' && object.attribute2==='green'){
     //run my function looking for these specific values
     //EXCLUDE attribute3 from above statement bc it's blank!
}

how do I dynamically 'build' that if statement?

Aucun commentaire:

Enregistrer un commentaire