MDN wants to learn about developers like you: https://qsurvey.mozilla.com/s3/MDN-dev-survey

현재 번역은 완벽하지 않습니다. 한국어로 문서 번역에 동참해주세요.

propertyIsEnumerable() 메소드는 특정 속성이 열거가능한지 여부를 나타내는 Boolean을 반환합니다.

구문

obj.propertyIsEnumerable(prop)

매개변수

prop
테스트 할 속성의 이름.

반환 값

특정 속성이 열거가능한지 여부를 나타내는 Boolean.

설명

Every object has a propertyIsEnumerable method. This method can determine whether the specified property in an object can be enumerated by a for...in loop, with the exception of properties inherited through the prototype chain. If the object does not have the specified property, this method returns 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 Status Comment
ECMAScript 3rd Edition (ECMA-262) Standard Initial definition
ECMAScript 5.1 (ECMA-262)
The definition of 'Object.prototype.propertyIsEnumerable' in that specification.
Standard  
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Object.prototype.propertyIsEnumerable' in that specification.
Standard  
ECMAScript 2017 Draft (ECMA-262)
The definition of 'Object.prototype.propertyIsEnumerable' in that specification.
Draft  

브라우저 호환성

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) (Yes)[1] (Yes) (Yes) (Yes)
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes)[1] (Yes) (Yes) (Yes)

[1] Starting in JavaScript 1.8.1 (in Gecko 1.9.2 (Firefox 3.6 / Thunderbird 3.1 / Fennec 1.0)), propertyIsEnumerable('prototype') returns false instead of true; this makes the result compliant with ECMAScript 5.

관련 참고

문서 태그 및 공헌자

 이 페이지의 공헌자: dotorify
 최종 변경: dotorify,