This article describes how to check the existence of object property in JavaScript. This article describes four methods to check whether an object o has propertyx. For more information, see in JavaScript, you can use four methods to check whether an object o has property x:
1. "x" in o. The in operator can be used to check whether the property x exists in object o. X can be an object's Own (Own Property) or inherited from the prototype object. x can be an enumerable property or a non-enumerable property.
2. o. x. You can access the o. x statement and determine whether the result is undefined to check whether x exists. its scope is the same as that of the in operator. Unlike the in operator, if the value of a property x is explicitly declared as undefined in object o, the "x" in o operation result will be true, while the o. the x result is undefined.
3. hasOwnProperty (). O. hasOwnProperty ("x") operations are used to determine whether the o object itself has x property. The property inherited from the prototype object will not be considered. The hasOwnProperty () operation checks both the property of enumerable and the property of non-enumerable.
4. propertyIsEnumerable (). The o. propertyIsEnumerable ("x") operation only checks the enumerable property of the o object. this operation is a subset of hasOwnProperty.
The above information is summarized as follows: