Module 3 · Lesson 4 of 412/32 in the course~16 min
Module lessons (4/4)
Iterating over collections
Lesson preview5 hands-on exercises readyJavaScript Course · Module 3 — Arrays and objects
for…of on arrays, for…in on objects, Object.keys/values/entries.
What you'll learn in this lesson
- Iterate array with
for...ofand access index+value with.entries(). - Avoid the pitfalls of
for...inon arrays and objects withObject.keys,Object.values,Object.entries. - Transform objects into arrays of
[key, value]pairs and reconstruct them withObject.fromEntries. - Choose between imperative loops (
for,for...of) and functional methods without accidental mutations.
Overview
Choosing the right loop makes it immediately clear what you are iterating: for...of extracts the values of any iterable (arrays, strings, Set, Map), while Object.entries(obj) transforms the properties of an object into [chiave, valore] pairs ready to be iterated or filtered.
Sections covered in this lesson
- 1Mental model: the right construct for each structure
- 2Progressive examples
- 3Guided laboratory
- 4Check for understanding
Pro Lesson · Module 3 — Arrays and objects
Unlock "Iterating over collections" and the full JavaScript Course curriculum
for…of on arrays, for…in on objects, Object.keys/values/entries.
Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.
- Instant access to all advanced modules in JavaScript Course plus 17 more courses
- Hands-on browser exercises with automated test suites and solutions
- 14-day money-back guarantee processed via Paddle.com
14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.