Skip to main content

for…in vs for…of and array iteration

Which loop yields keys, which yields values, and why is for…in a poor default for arrays?

Official Reference

Model Answer & Explanation

for…in yields enumerable string property keys, including inherited keys. for…of consumes an iterable’s values, such as array elements. Plain objects are not iterable by default. Use Object.entries for their own enumerable string-keyed entries, or for…of for array values.

Follow-up Interview Question · How do a sparse slot and an extra named array property behave under each loop?

Module Context & References

JavaScript · Language theory Explain scope, closures, this, prototypes, equality and references
Personal Notes · Markdown

Technologies & Interview Topics Covered

Switch between short-term interview tracks and long-term 80/20 engineering depth to practice JavaScript internals, React rendering and hooks, timed frontend machine coding UI challenges, MeetaPro FG300, Blind 75 & NeetCode 150 DSA patterns, Python & FastAPI APIs, PostgreSQL query optimization & MVCC, Redis caching, Applied AI RAG pipelines & evaluations, and distributed system design.