Imagine this scenario:
var myObject = {
"1030":{},
"1059":{}
}
I want to check if 1030
is in that object.
How would I do this?
Imagine this scenario:
var myObject = {
"1030":{},
"1059":{}
}
I want to check if 1030
is in that object.
How would I do this?
Try hasOwnProperty
if(myObject.hasOwnProperty("1030")) {
// Do code
}
It's a bit safer than checking if(myObject["1030"])
. This will return false, if the value is falsey (false
, undefined
, null
), which may be desirable, but also does not strictly mean it does not exist.