java-script:for-in-vs-for-of
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| java-script:for-in-vs-for-of [2023/08/10 00:02] – odefta | java-script:for-in-vs-for-of [2025/01/02 18:22] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 18: | Line 18: | ||
| </ | </ | ||
| - | ==== Example with an array ==== | + | ==== Example with an Array ==== |
| <code javascript> | <code javascript> | ||
| const arr = [10, 20, 30]; | const arr = [10, 20, 30]; | ||
| Line 75: | Line 75: | ||
| However, you can convert an object' | However, you can convert an object' | ||
| Example: | Example: | ||
| - | < | + | < |
| const person = { | const person = { | ||
| name: ' | name: ' | ||
| Line 111: | Line 111: | ||
| In this example, **Object.keys(person)**, | In this example, **Object.keys(person)**, | ||
| - | ====== Conclusion | + | ===== Conclusion ===== |
| * Use **for...in** to iterate over the **keys** of an **object** (including non-array objects). | * Use **for...in** to iterate over the **keys** of an **object** (including non-array objects). | ||
java-script/for-in-vs-for-of.1691625722.txt.gz · Last modified: (external edit)
