Skip to content

Commit 8e11a64

Browse files
authored
Fix iteration over author object using Object.values
Updated loop to use Object.values for iterating over a plain object.
1 parent 18c60e7 commit 8e11a64

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎Sprint-2/debug/author.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,19 @@ const author = {
1414
for (const value of author) {
1515
console.log(value);
1616
}
17+
18+
// this code will throw an error because on line for 14 it is trying to loop a plain object.
19+
20+
const author = {
21+
firstName: "Zadie",
22+
lastName: "Smith",
23+
occupation: "writer",
24+
age: 40,
25+
alive: true,
26+
};
27+
28+
for (const value of Object.values(author)) {
29+
console.log(value);
30+
}
31+
32+
//we fix this by using Object.values, i.e. turning plain object in an array.

0 commit comments

Comments
 (0)