Object.prototype.propertyIsEnumerable()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since 2015ë 7ì.
propertyIsEnumerable() ë©ìëë í¹ì ìì±ì´ ì´ê±°ê°ë¥íì§ ì¬ë¶ë¥¼ ëíë´ë ë¶ë¦¬ì¸ ê°ì ë°íí©ëë¤.
ìëí´ ë³´ê¸°
const object1 = {};
const array1 = [];
object1.property1 = 42;
array1[0] = 42;
console.log(object1.propertyIsEnumerable("property1"));
// Expected output: true
console.log(array1.propertyIsEnumerable(0));
// Expected output: true
console.log(array1.propertyIsEnumerable("length"));
// Expected output: false
구문
obj.propertyIsEnumerable(prop);
매ê°ë³ì
prop-
í ì¤í¸ í ìì±ì ì´ë¦.
ë°í ê°
í¹ì ìì±ì´ ì´ê±°ê°ë¥íì§ ì¬ë¶ë¥¼ ëíë´ë Boolean.
ì¤ëª
모ë ê°ì²´ë propertyIsEnumerable ë©ìë를 ê°ì§ê³ ììµëë¤. ì´ ë©ìëë íë¡í íì
ì²´ì¸ì íµí´ ììë í¹ì±ì ì ì¸íê³ ê°ì²´ì ì§ì ë ìì±ì for...in 루íë¡ ì´ê±°í ì ìëì§ ì¬ë¶ë¥¼ íì¸í ì ììµëë¤. ê°ì²´ì ì§ì ë ìì±ì´ ìì¼ë©´ ì´ ë©ìëë false를 ë°íí©ëë¤.
ìì
>A basic use of propertyIsEnumerable
The following example shows the use of propertyIsEnumerable on objects and arrays:
var o = {};
var a = [];
o.prop = "is enumerable";
a[0] = "is enumerable";
o.propertyIsEnumerable("prop"); // returns true
a.propertyIsEnumerable(0); // returns true
User-defined versus built-in objects
The following example demonstrates the enumerability of user-defined versus built-in properties:
var a = ["is enumerable"];
a.propertyIsEnumerable(0); // returns true
a.propertyIsEnumerable("length"); // returns false
Math.propertyIsEnumerable("random"); // returns false
this.propertyIsEnumerable("Math"); // returns false
Direct versus inherited properties
var a = [];
a.propertyIsEnumerable("constructor"); // returns false
function firstConstructor() {
this.property = "is not enumerable";
}
firstConstructor.prototype.firstMethod = function () {};
function secondConstructor() {
this.method = function method() {
return "is enumerable";
};
}
secondConstructor.prototype = new firstConstructor();
secondConstructor.prototype.constructor = secondConstructor;
var o = new secondConstructor();
o.arbitraryProperty = "is enumerable";
o.propertyIsEnumerable("arbitraryProperty"); // returns true
o.propertyIsEnumerable("method"); // returns true
o.propertyIsEnumerable("property"); // returns false
o.property = "is enumerable";
o.propertyIsEnumerable("property"); // returns true
// These return false as they are on the prototype which
// propertyIsEnumerable does not consider (even though the last two
// are iteratable with for-in)
o.propertyIsEnumerable("prototype"); // returns false (as of JS 1.8.1/FF3.6)
o.propertyIsEnumerable("constructor"); // returns false
o.propertyIsEnumerable("firstMethod"); // returns false
ëª ì¸
| Specification |
|---|
| ECMAScript® 2027 Language Specification> # sec-object.prototype.propertyisenumerable> |