| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 7.
Object hasOwnProperty()
( ) .
Note:
Object.hasOwn().hasOwnProperty().
const object1 = {};
object1.property1 = 42;
console.log(object1.hasOwnProperty("property1"));
// Expected output: true
console.log(object1.hasOwnProperty("toString"));
// Expected output: false
console.log(object1.hasOwnProperty("hasOwnProperty"));
// Expected output: false
hasOwnProperty(prop)
true false .
hasOwnProperty() null undefined true . false . in , .
JavaScript . Object , . Array Object hasOwnProperty() .
const fruits = ["Apple", "Banana", "Watermelon", "Orange"];
fruits.hasOwnProperty(3); // true ('Orange')
fruits.hasOwnProperty(4); // false - not defined
Object.prototype null .
example prop .
const example = {};
example.hasOwnProperty("prop"); // false
example.prop = "exists";
example.hasOwnProperty("prop"); // true - 'prop' .
example.prop = null;
example.hasOwnProperty("prop"); // true - null .
example.prop = undefined;
example.hasOwnProperty("prop"); // true - undefined .
.
const example = {};
example.prop = "exists";
// `hasOwnProperty` true .
example.hasOwnProperty("prop"); // true
example.hasOwnProperty("toString"); // false
example.hasOwnProperty("hasOwnProperty"); // false
// `in` true .
"prop" in example; // true
"toString" in example; // true
"hasOwnProperty" in example; // true
.
const buz = {
fog: "stack",
};
for (const name in buz) {
if (buz.hasOwnProperty(name)) {
console.log(`this is fog (${name}) for sure. Value: ${buz[name]}`);
} else {
console.log(name); // toString
}
}
for...in . hasOwnProperty . Object.getOwnPropertyNames() .
JavaScript hasOwnProperty . .
const foo = {
hasOwnProperty() {
return false;
},
bar: "Here be dragons",
};
foo.hasOwnProperty("bar"); // false .
Object.hasOwn() . hasOwnProperty .
const foo = { bar: "Here be dragons" };
// Object.hasOwn() . -
Object.hasOwn(foo, "bar"); // true
// Object hasOwnProperty
Object.prototype.hasOwnProperty.call(foo, "bar"); // true
// Object hasOwnProperty
// 'this' call foo .
({}).hasOwnProperty.call(foo, "bar"); // true
.
null Object.prototype hasOwnProperty() .
const foo = Object.create(null);
foo.prop = "exists";
foo.hasOwnProperty("prop"); // Uncaught TypeError: foo.hasOwnProperty is not a function
. Object.hasOwn() hasOwnProperty() .
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-object.prototype.hasownproperty |
This page was last modified on 2025 6 27 by MDN contributors.
ObjectObject.assign()Object.create()Object.defineProperties()Object.defineProperty()Object.entries()Object.freeze()Object.fromEntries()Object.getOwnPropertyDescriptor()Object.getOwnPropertyDescriptors()Object.getOwnPropertyNames()Object.getOwnPropertySymbols()Object.getPrototypeOf()Object.groupBy()Object.hasOwn()Object.is()Object.isExtensible()Object.isFrozen()Object.isSealed()Object.keys()Object.preventExtensions()Object.seal()setPrototypeOf()Object.values()Object.prototype.__defineGetter__()Object.prototype.__defineSetter__()Object.prototype.__lookupGetter__()Object.prototype.__lookupSetter__()Object.prototype.hasOwnProperty()Object.prototype.isPrototypeOf()Object.prototype.propertyIsEnumerable()Object.prototype.toLocaleString()Object.prototype.toString()Object.prototype.valueOf()Object/FunctionObject.prototype.__defineGetter__()Object.prototype.__defineSetter__()Object.prototype.__lookupGetter__()Object.prototype.__lookupSetter__()Object.prototype.hasOwnProperty()Object.prototype.isPrototypeOf()Object.prototype.propertyIsEnumerable()Object.prototype.toLocaleString()Object.prototype.toString()Object.prototype.valueOf()Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |