User Tools

Site Tools


java-script:for-in-vs-for-of

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
java-script:for-in-vs-for-of [2023/08/10 03:02] odeftajava-script:for-in-vs-for-of [2023/08/11 12:22] (current) odefta
Line 75: Line 75:
 However, you can convert an object's keys, values, or key-value pairs into an array and then iterate over that array with a for...of loop. \\  However, you can convert an object's keys, values, or key-value pairs into an array and then iterate over that array with a for...of loop. \\ 
 Example: Example:
-<code>+<code javascript>
 const person = { const person = {
   name: 'Alice',   name: 'Alice',
Line 111: Line 111:
 In this example, **Object.keys(person)**, **Object.values(person**), and **Object.entries(person)** return arrays of the object's keys, values, and key-value pairs, respectively, allowing you to iterate over them with a **for...of** loop. In this example, **Object.keys(person)**, **Object.values(person**), and **Object.entries(person)** return arrays of the object's keys, values, and key-value pairs, respectively, allowing you to iterate over them with a **for...of** loop.
  
-====== 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.1691625735.txt.gz · Last modified: 2023/08/10 03:02 by odefta