Finding property in Object
This question already has an answer here:
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.
下一篇: 在Object中查找属性