# JS Tip of the Day: What Uses enumerable?

**URL:** <https://forum.kirupa.com/t/js-tip-of-the-day-what-uses-enumerable/643130>\
**Category:** web dev\
**Created:** [April 6, 2020, 3:09pm UTC](https://forum.kirupa.com/t/js-tip-of-the-day-what-uses-enumerable/643130 "2020-04-06T15:09:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [April 6, 2020, 3:09pm UTC](https://forum.kirupa.com/t/js-tip-of-the-day-what-uses-enumerable/643130/1 "2020-04-06T15:09:17Z")

</div>

**What Uses enumerable?**  
Level: Intermediate

When a property is enumerable, it means it will appear in normal property enumeration, which is when you go through the properties of an object in, for example, a `for...in` loop. As a `for...in` goes over the keys of an object, it will ignore non-enumerable properties completely. To get or set this characteristic using `Object.getOwnPropertyDescriptor()` and `Object.describeProperty()`.

```javascript
let mixed = {
    tapes: ['summer of 1969'],
    emotions: ['happy', 'sad'],
};
Object.defineProperty(mixed, 'emotions', { enumerable: false });

for (let key in mixed) {
    console.log('Found key:', key);
}
/* logs
Found key: tapes
*/

```

Not everything checks properties for being enumerable. There are certain APIs which skip that check and will recognize non-enumerable properties along with the enumerable ones. The following is a list of statements and APIs that do and do not respect enumerable.

- Recognizes enumerable:

- Ignores enumerable:

You’d most commonly be using those listed under recognizing enumerable. Those that don’t largely exist as alternatives to others that would allow you to get to the non-enumerables when you’d explicitly want them.

```javascript
let mixed = {
    tapes: ['summer of 1989'],
    emotions: ['happy', 'sad'],
};
Object.defineProperty(mixed, 'emotions', { enumerable: false });

console.log(Object.keys(mixed)); // ['tapes']
console.log(Reflect.ownKeys(mixed)); // ['tapes', 'emotions']

```

You may notice that `for...of` is not in this list. That’s because `for...of` is dependent on the iterable its looping over. That iterable determines what is provided in the loop. Arrays are one of the more common iterables that might be used with `for...of`. Their iterators do not look at object properties or their enumerable values, rather they go through an array’s indexed property values from 0 up to the array’s `length` whether or not they even exist, let alone enumerable.

More info:

- [for…in on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in)
- [JSON on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON)
- [Object on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
- [Reflect on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect)
- [for…of on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of)
