liveBook · Manning

Enumerable property

As explained in Secrets of the JavaScript Ninja, Third Edition

An enumerable property is an object property whose enumerable attribute allows it to be included by specified property-iteration and copying operations.

An enumerable property is eligible for inclusion in specified object iteration and copying operations. Properties created with Object.defineProperty are non-enumerable by default; set enumerable: true in the descriptor to include one. Non-enumerable properties are excluded from Object.keys, Object.values, Object.entries, for…in, for…of, JSON.stringify, Object.assign, and object spread. Enumerable symbol-keyed properties are still ignored by loops and methods such as Object.keys and JSON.stringify. section 9.1.2

// Object from Listing 9.1
Object.keys(ninjaCollection)
> [ 'ninjas', 'firstNinja' ]
 
// Object from Listing 9.2
Object.keys(ninjaCollection)
> [ 'ninjas' ]

Compare Object.keys results to see how a property’s enumerability changes which keys are returned. section 9.1.2

How Secrets of the JavaScript Ninja, Third Edition covers it

How deep it goes
Defines the descriptor flag and lists affected operations without detailing their algorithms.
Examples
Contrasts Object.keys results for two ninjaCollection objects and demonstrates setting enumerable: true.
What you can do after
Apply it via Object.defineProperty to control which properties appear in enumeration and copying.
How it connects
Connects property descriptors with Object.defineProperty, Object.keys, JSON.stringify, object spread, and symbols.

Also explained in

Compare how 3 books explain enumerable property →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Secrets of the JavaScript Ninja, Third Edition. The section links point to the parts of the book it draws on.