this is blowing up
if (myObject.myKey.myThing){
}
cannot read myThing of undefined
how can this be written in a way that if it is defined it goes into the if block, and if it not it does not?
this is blowing up
if (myObject.myKey.myThing){
}
cannot read myThing of undefined
how can this be written in a way that if it is defined it goes into the if block, and if it not it does not?
Add another check to see if myObject.myKey
exists -
if (myObject.myKey && myObject.myKey.myThing){
}
you would use the hasOwnProperty method, like so
if (myObject.hasOwnProperty('myKey')) {
...
}
You would want to use this as opposed to just checking the value of the keys because then if the value of that key is a false equivalent value your code won't run