In the book of David Flanagan in the chapter “Properties and Methods of the Universal Object Class”, he encountered the term enumerated and non-enumerated properties. Once there are enumerated properties, then there are non enumerable properties. I would like to know what these properties are and how they differ. On the Internet I did not find anything suitable on this topic. Therefore, I ask for help here. Thank you all in advance.


Excerpt from the book:

Note: all user-defined object properties are enumerable. Inherited properties are usually not enumerated (the topic of property inheritance is discussed in Chapter 9), so this method almost always returns the same value as the hasOwnProperty() method.

  • can you add a quote from the book? - Grundy
  • added, see the updated answer - perfect
  • uh ... I can't see the words enumerated data type - Grundy
  • pay attention to the words - are enumerated - this moment is not clear to me - perfect
  • professorweb.ru/my/javascript/js_theory/level1/1_7.php here look - speech about enumerable - lexxl

3 answers 3

The quotation deals with the properties of the object.

They can be enumerated and not enumerable.

If the property is enumerable, then it will be possible to get it when traversing in a for..in loop; if not enumerable, it is impossible.

For example:

 var o = { e: "prop" }; for (var i in o) { document.write('свойство "' + i + '" перечислимое'); } document.write('<br/>свойство toString не перечислимое: '+o.toString) 

  • what you need, thank you - perfect

It is logical to assume that we are talking about arrays and objects with similar semantics.

That is, something that contains the properties-indices and the (hidden) property length .


If we talk about ES6, then we can include generators here, as well as recall Symbol.iterator and the for cycle, which allows iteration over the collection.

PS: I did not read the book.

  • one
    judging by the update - it meant enumerable and not enumerable property - Grundy
  • @Grundy, I wrote before updating the question. - Qwertiy
  • yeah :-) but the question has been updated :) it’s worth updating and the answer is :-) - Grundy
  • @Grundy, what to add? Rather, delete? Then I will wait for -3, since someone has placed a minus. - Qwertiy

That HERE outlined all the info that I found on my own and the listed properties of the object. Also told how to make your OWN property!

 let object = { enumProp1: '1', enumProp2: '2', enumProp3: '3', }; // Явное определение НЕПЕРЕЧИСЛЯЕМОГО (собственного) свойства Object.defineProperty(object, 'key', { enumerable: false, // - флаг который какраз делает его НЕ перечисляемым!!! если изменить на true, то будет перечисляемым!!! }); for (key in object) { document.write(`${key}<br>`); // все перечисляемые свойства можно перечислить For } //Так же не перечисляемыми свойствами являются те, которые унаследованы от дургих или просто ядвляются внутренними и закрытыми document.write('<br/>свойство toString не перечисляемое (собственное): '+ object.toString); // БОЛЬШЕ ИНФЫ ТУТ https://developer.mozilla.org/ru/docs/Web/JavaScript/Enumerability_and_ownership_of_properties