๐for-of
`for ( const value of iterable)` syntax. ๐ง -> TypeError
JSโฉ syntax โฉ for loops โฉ for-of
for (const value of iterable) {} // loop over "values"
for (lvalue of iterable) {} // lvalue can be used
for (const [key, value] of aMap) {} // iterate over a Map.
(by default) object is not iterableโ
let obj = { x: 1, y: 2, z: 3 };
for (let value of obj) { } // TypeError
// workarounds
for (let key of Object.keys(obj) { ... }
for (let key in obj) { ... } // for-in
for (let value of Object.values(obj) { ... }
for (let [key, value] of Object.entries(obj) { ... }
can be used with for-in / for-of loop.
can't be used with a classic for-loop.
๐ no const for classic "for"โ
โญ๏ธ ๆณจๆ๏ผ for-in, for-of ๆ "(...)
" ๆฌ่โ๏ธ
for (let key in object) {} // loop over "keys"
for (let value of object) {} // loop over "values"
// ^ ^ // โญ๏ธ ( ... )
๐ Property flags and descriptors - โflags-awareโ cloneูญ
Object.entries()
โObject.keys()
+Object.values()
โ
๏ผไปฃ่กจใ็ฏๅไธๆจฃใ
โ ๏ผstring / symbol | โ๏ผnot available | ๐ค๏ผString | ๐บ๏ผSymbol
method/operator
own enum
own nonenum
inherited enum
inherited nonenum
๐ property enumeration (๐ MSN )
lvalue can be used to receive the iteration value of a for-of loop.
"pure" object is an object without prototype.
Last updated