๐for-in
loop over "keys"
JSโฉ syntax โฉ for loops โฉ for-in
iterates over all (own/inherited) enumerable string properties of an object (ignoring properties keyed by symbols).
for (const <key> in obj) {} // loop over "keys"
for (<variable> in obj) {}
// <variable> can be a let/const/var, or an "lvalue" (assignment target). 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 iterable) {} // loop over "values"
// ^ ^ ๐ Property flags and descriptors - โflags-awareโ clone
โ ๏ผstring / symbol | โ๏ผnot available | ๐ค๏ผString | ๐บ๏ผSymbol
method/operator
own enum
own nonenum
inherited enum
inherited nonenum
๐ property enumeration (๐ MSN )
"pure" object is an object without prototype.
lvalue can be used in for-in/for-of.
parentheses () are used in for-in/for-of.
let animal = {
eats: true
};
let rabbit = {
jumps: true,
__proto__: animal
};
// own keys
Object.keys(rabbit) // "jumps"
// inherited included
for(let prop in rabbit) log(prop) // "jumps", "eats"Object.prototype โฉ
Last updated
Was this helpful?