Differences
This shows you the differences between two versions of the page.
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}: | ||
+ | } | ||
+ | |||
+ | // "a: 1" | ||
+ | // "b: 2" | ||
+ | // "c: 3" | ||
+ | </ | ||
---- | ---- | ||
- | ===== 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: | + | // " |
- | // output: | + | // " |
- | // output: | + | // " |
</ | </ | ||
+ | ---- |