In JavaScript, there are four ways to check whether an object o owns property x:
1. "X" in O. The in operator can be used to check if there is an X in Object o. X can be the object itself (Own property), or it can be inherited from a prototype object; X can be a enumerable property, or it can be a enumerable property.
2.o.x. The o.x statement can be accessed to determine whether the result is undefined to confirm that x exists and that the scope of the action is the same as in the in operator. Unlike the In operator: if you explicitly declare the value of a property x to be undefined in object o, the "x" in O operation results will be true, and the o.x result is undefined.
3.hasOwnProperty (). The O.hasownproperty ("x") operation is used to determine whether the O object itself owns X Property,o the property that inherits from the prototype object will not be considered. The hasOwnProperty () operation checks both the enumerable property and the non enumerable property.
4.propertyIsEnumerable (). The O.propertyisenumerable ("x") operation checks only the enumerable property owned by the O object itself, which is a subset of hasOwnProperty ().
Combined with the above information, summarized in the following diagram: