Export (0) Print
Expand All

hasOwnProperty Method (JavaScript)

Returns a Boolean value indicating whether an object has a property with the specified name.

object.hasOwnProperty(proName)

object

Required. Instance of an object.

proName

Required. String value of a property name.

The hasOwnProperty method returns true if object has a property of the specified name, false if it does not. This method does not check if the property exists in the object's prototype chain; the property must be a member of the object itself.

In the following example, all String objects share a common split method. The following code will display false and true.

var s = new String("Sample");
document.write(s.hasOwnProperty("split"));
document.write(String.prototype.hasOwnProperty("split"));

Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards. See Version Information.

Applies To: Object Object (JavaScript)

Community Additions

Show:
© 2014 Microsoft