Skip to content

Commit 9394322

Browse files
authored
Fix iteration over author object
Replace for...of loop with for...in loop to iterate over object properties.
1 parent 35fceee commit 9394322

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎Sprint-2/debug/author.js‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ const author = {
1111
alive: true,
1212
};
1313

14-
for (const value of author) {
15-
console.log(value);
14+
for (const key in author) {
15+
console.log(author[key]);
1616
}
17+
18+
//TypeError: author is not iterable
19+
// The for...of loop only works on iterable objects in JavaScript—such as Arrays, Strings, Sets, and Maps.
20+
// Plain JavaScript objects ({}) are not iterable by default because they don't have a built-in [Symbol.iterator] method.
21+
// use a for...in loop to step through the keys, then access each value using bracket notation

0 commit comments

Comments
 (0)