Differences

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

Link to this comparison view

Next revision
Previous revision
development:javascript:looping [2020/10/12 17:49]
kalenpw created
development:javascript:looping [2021/06/29 15:03] (current)
kalenpw
Line 2: Line 2:
 ---- ----
  
-===== For x in y =====+===== for x in y ===== 
 +Used for iterating over objects 
 +<code javascript> 
 +const object = { a: 1, b: 2, c: 3 }; 
 + 
 +for (const property in object) { 
 +  console.log(`${property}: ${object[property]}`); 
 +
 + 
 +// "a: 1" 
 +// "b: 2" 
 +// "c: 3" 
 +</code> 
  
 ---- ----
-===== For x of y =====+===== for x of y =====
 Used for strings, arrays, array-like objects Used for strings, arrays, array-like objects
 <code javascript> <code javascript>
Line 14: Line 27:
 } }
  
-// output: "a" +// "a" 
-// output: "b" +// "b" 
-// output: "c"+// "c"
  
 </code> </code>
 +----