๐Ÿ”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). 

const

  • 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

Last updated