-
-
Notifications
You must be signed in to change notification settings - Fork 286
Expand file tree
/
Copy pathauthor.js
More file actions
16 lines (14 loc) · 669 Bytes
/
Copy pathauthor.js
File metadata and controls
16 lines (14 loc) · 669 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Predict and explain first...
// The program does not work because for...of can only be used on iterable objects such as arrays or strings. The author variable is an object, which is not iterable by default. To fix the problem we can use Object.values(author) to convert the object values into an iterable array and then loop through them.
// This program attempts to log out all the property values in the object.
// But it isn't working. Explain why first and then fix the problem
const author = {
firstName: "Zadie",
lastName: "Smith",
occupation: "writer",
age: 40,
alive: true,
};
for (const value of Object.values(author)) {
console.log(value);
}