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 July 2015.

O método propertyIsEnumerable() retorna um booleano indicando quando a propriedade especificada é enumerável e é a propriedade do próprio objeto

Experimente

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

Sintaxe

obj.propertyIsEnumerable(prop)

Parâmetros

prop

O nome da propriedade para teste

Valor de Retorno

O Boolean indicando se a propriedade especificada é enumeravel e é a propriedade do objeto

Descrição

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.

Exemplos

O uso basico de propertyIsEnumerable

O exemplos a seguir mostram o uso de propertyIsEnumerable em um objeto e um array:

js
var o = {};
var a = [];
o.prop = "is enumerable";
a[0] = "is enumerable";

o.propertyIsEnumerable("prop"); // returns true
a.propertyIsEnumerable(0); // returns true

Objetos User-defined vs. built-in

Os exemplos a seguir demostram a enumerabilidade da propriedade user-defined vs. built-in :

js
var a = ["is enumerable"];

a.propertyIsEnumerable(0); // returns true
a.propertyIsEnumerable("length"); // returns false

Math.propertyIsEnumerable("random"); // returns false
this.propertyIsEnumerable("Math"); // returns false

Propriedade Direct vs. inherited

js
var a = [];
a.propertyIsEnumerable("constructor"); // returns false

function firstConstructor() {
  this.property = "is not enumerable";
}

firstConstructor.prototype.firstMethod = function () {};

function secondConstructor() {
  this.method = function () {
    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

Especificações

Specification
ECMAScript® 2025 Language Specification
# sec-object.prototype.propertyisenumerable

Compatibilidade com navegadores

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
propertyIsEnumerable

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

Veja também