Skip to Main Content
JavaScript: The Definitive Guide, Fourth Edition
book

JavaScript: The Definitive Guide, Fourth Edition

by David Flanagan
November 2001
Intermediate to advanced content levelIntermediate to advanced
936 pages
68h 43m
English
O'Reilly Media, Inc.
Content preview from JavaScript: The Definitive Guide, Fourth Edition

Name

Object.propertyIsEnumerable( ) — will property be seen by a for/in loop?

Availability

JavaScript 1.5; JScript 5.5; ECMAScript v3

Synopsis

                  object.propertyIsEnumerable(propname)

Arguments

propname

A string that contains the name of a property of object.

Returns

true if object has a noninherited property with the name specified by propname and if that property is “enumerable,” which means that it would be enumerated by a for/in loop on object.

Description

The for/in statement loops through the “enumerable” properties of an object. Not all properties of an object are enumerable, however: properties added to an object by JavaScript code are enumerable, but the predefined properties (such as methods) of built-in objects are not usually enumerable. The propertyIsEnumerable( ) method provides a way to distinguish between enumerable and nonenumerable properties. Note, however, that the ECMAScript specification states that propertyIsEnumerable( ) does not examine the prototype chain, which means that it only works for local properties of an object and does not provide any way to test the enumerability of inherited properties.

Example

var o = new Object( ); // Create an object o.x = 3.14; // Define a property o.propertyIsEnumerable("x"); // true: property x is local and enumerable o.propertyIsEnumerable("y"); // false: o doesn't have a property y o.propertyIsEnumerable("toString"); // false: toString property is inherited Object.prototype.propertyIsEnumerable("toString"); // false: nonenumerable ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

JavaScript: A Beginner's Guide, Fourth Edition, 4th Edition

JavaScript: A Beginner's Guide, Fourth Edition, 4th Edition

John Pollock
Coding with JavaScript For Dummies

Coding with JavaScript For Dummies

Chris Minnick, Eva Holland

Publisher Resources

ISBN: 0596000480Supplemental ContentCatalog PageErrata