# property enumeration

* [JS](../../..) ⟩ [value](../..) ⟩ [object](..) ⟩ [property]() ⟩ enumerating properties&#x20;

{% hint style="success" %}
enumerate through [**properties**]() of an object.

```javascript
for (const key in obj) { ... }
for (const value of iterable) { ... }    // object is not iterable by default.
```
{% endhint %}

\|  ✅：<mark style="color:green;">**string / symbol**</mark>   |  🔤：String  | 🔺：Symbol

<table><thead><tr><th width="282">method/operator</th><th width="110">own enum<select><option value="fa493c02131745babc72fa4cfd60f1bf" label="✅" color="blue"></option><option value="575cf73897dd4bbab4db839c76bf6f75" label="❌" color="blue"></option><option value="c6f507edd61f4f1f91a69d2c98ee17b9" label="🔤" color="blue"></option><option value="42baee63b5df424b8d1718fcad2a1700" label="🔺" color="blue"></option></select></th><th width="105">own nonenum<select><option value="92aacf9c25cc45758898e9cea377838c" label="✅" color="blue"></option><option value="186e2fd65cb541ed828129ae4de3338d" label="❌" color="blue"></option><option value="2412011063cb469a831045674ba4de1b" label="🔤" color="blue"></option><option value="1fd8ca36728a49a180716097753710dd" label="🔺" color="blue"></option></select></th><th width="105">inherited enum<select><option value="ae58de58a03140a1ac9a7bb88c048855" label="✅" color="blue"></option><option value="ca78ad327cf849e5921fd1334fab4b59" label="❌" color="blue"></option><option value="8ecf7ff7d50d44af8f3a3a6978771c0e" label="🔤" color="blue"></option></select></th><th width="107">inherited nonenum<select><option value="2029a71aaf8c4baaac53af637338d80b" label="✅" color="blue"></option><option value="50730b3459424472be062a6ecb9f9fad" label="❌" color="blue"></option></select></th></tr></thead><tbody><tr><td><a href="../extend/object.assign"><strong>Object.assign()</strong></a> </td><td><span data-option="fa493c02131745babc72fa4cfd60f1bf">✅</span></td><td></td><td></td><td></td></tr><tr><td><a href="../../../grammar/op/spread"><strong>...obj</strong></a></td><td><span data-option="fa493c02131745babc72fa4cfd60f1bf">✅</span></td><td></td><td></td><td></td></tr><tr><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys">.keys()</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values">.values()</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries">.entries()</a></td><td><span data-option="c6f507edd61f4f1f91a69d2c98ee17b9">🔤</span></td><td></td><td></td><td></td></tr><tr><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames">.getOwnPropertyNames()</a> </td><td><span data-option="c6f507edd61f4f1f91a69d2c98ee17b9">🔤</span></td><td><span data-option="2412011063cb469a831045674ba4de1b">🔤</span></td><td></td><td></td></tr><tr><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols">.getOwnPropertySymbols()</a> </td><td><span data-option="42baee63b5df424b8d1718fcad2a1700">🔺</span></td><td><span data-option="1fd8ca36728a49a180716097753710dd">🔺</span></td><td></td><td></td></tr><tr><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors">.getOwnPropertyDescriptors()</a> </td><td><span data-option="fa493c02131745babc72fa4cfd60f1bf">✅</span></td><td><span data-option="92aacf9c25cc45758898e9cea377838c">✅</span></td><td></td><td></td></tr><tr><td>.<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn">hasOwn</a>()</td><td><span data-option="fa493c02131745babc72fa4cfd60f1bf">✅</span></td><td><span data-option="92aacf9c25cc45758898e9cea377838c">✅</span></td><td></td><td></td></tr><tr><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/ownKeys">Reflect.ownKeys()</a> </td><td><span data-option="fa493c02131745babc72fa4cfd60f1bf">✅</span></td><td><span data-option="92aacf9c25cc45758898e9cea377838c">✅</span></td><td></td><td></td></tr><tr><td><a data-mention href="../../../grammar/statement/loop/for/in">in</a> (loop over keys)</td><td><span data-option="c6f507edd61f4f1f91a69d2c98ee17b9">🔤</span></td><td></td><td><span data-option="8ecf7ff7d50d44af8f3a3a6978771c0e">🔤</span></td><td></td></tr><tr><td><a data-mention href="../../../grammar/statement/loop/for/of">of</a> (loop over values)</td><td><span data-option="c6f507edd61f4f1f91a69d2c98ee17b9">🔤</span></td><td></td><td><span data-option="8ecf7ff7d50d44af8f3a3a6978771c0e">🔤</span></td><td></td></tr></tbody></table>

📘 [MSN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties) &#x20;

{% tabs %}
{% tab title="⭐️" %}
{% hint style="success" %}
Every [**property**]() in JavaScript [**objects**](..) can be <mark style="color:yellow;">**classified by**</mark>**&#x20;**<mark style="color:orange;">**3**</mark>**&#x20;**<mark style="color:yellow;">**factors**</mark>:

* [**String**](../../prim/str) <mark style="color:yellow;">**/**</mark> [**Symbol**](../../prim/symbol)
* [**enumerable**](attr) <mark style="color:yellow;">**/**</mark>**&#x20;**<mark style="color:orange;">**non-enumerable**</mark>
* <mark style="color:orange;">**own**</mark>**&#x20;**<mark style="color:yellow;">**/**</mark>**&#x20;**<mark style="color:orange;">**inherited**</mark> (from the [**prototype chain**](../proto/chain))

📘 [MSN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties)&#x20;
{% endhint %}

{% hint style="warning" %}
a [**property**]() <mark style="color:yellow;">**will**</mark>**&#x20;**<mark style="color:red;">**not**</mark>**&#x20;**<mark style="color:yellow;">**be enumerated**</mark>**&#x20;**<mark style="color:red;">**if**</mark>&#x20;

* a property <mark style="color:yellow;">**by that**</mark>**&#x20;**<mark style="color:red;">**same**</mark>**&#x20;**<mark style="color:yellow;">**name**</mark> has already been enumerated
* a <mark style="color:red;">**non-enumerable**</mark> property <mark style="color:yellow;">**by that**</mark>**&#x20;**<mark style="color:red;">**same**</mark>**&#x20;**<mark style="color:yellow;">**name**</mark> has already been considered
{% endhint %}
{% endtab %}

{% tab title="🔴" %}
* [**enumerable**](attr) property.
* [in](../../../grammar/op/relational/in "mention") operator
* [for-in-vs.-for-of-vs.-in](../../../grammar/statement/loop/for/for-in-vs.-for-of-vs.-in "mention")
{% endtab %}

{% tab title="👥" %}
* [test](test "mention")
* [**Proxy**](../../builtin/proxy) intercepts <mark style="color:purple;">**property enumeration**</mark>.
* [**...obj**](../../../grammar/op/spread) adds [**all enumerable own**](enumerate) <mark style="color:yellow;">**properties**</mark> of an **object** to an [**object literal**](../create/obj).
{% endtab %}

{% tab title="⬇️" %}
* [merge-with](../../builtin/object/ext/merge-with "mention") - merge with other source objects.
{% endtab %}

{% tab title="📗" %}
* [x] [javascript-the-definitive-guide](../../../../master/ref/javascript-the-definitive-guide "mention") ⟩ 6.6 Enumerating Properties
{% endtab %}

{% tab title="📘" %}
* [ ] [Enumerability and ownership of properties ⭐️ ](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties)
* [ ] Object.prototype ⟩ &#x20;
  * [ ] [.hasOwnProperty()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty)
  * [ ] [.propertyIsEnumerable()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable)
* [ ] Object ⟩&#x20;
  * [ ] [.hasOwn()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
  * [ ] [.getOwnPropertyNames()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames)
* [ ] [for...in](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in)
* [ ] [in](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/in)
* [ ] [JavaScript Guide: Inheritance revisited](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain)
{% endtab %}
{% endtabs %}
