Skip to content

Commit caef2d3

Browse files
committed
complete looping objects keys values and entries
1 parent 1238a4a commit caef2d3

File tree

1 file changed

+21
-0
lines changed
  • 09-Data-Structure-Modern-Operators-and-Strings

1 file changed

+21
-0
lines changed

09-Data-Structure-Modern-Operators-and-Strings/script.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,3 +338,24 @@ const users = [{ name: "Eke", email: "hello@eke.com" }];
338338
console.log(users[0]?.name ?? "User array empty");
339339

340340
// 🔸Looping Objects, Keys, Values, and Entries🔸
341+
const properties = Object.keys(openingHours);
342+
console.log(properties);
343+
344+
let openStr = `We are open on ${properties.length} days: `;
345+
346+
for (const day of properties) {
347+
openStr += `${day}, `;
348+
}
349+
console.log(openStr);
350+
351+
const values = Object.values(openingHours);
352+
console.log(values);
353+
354+
// Entries Object
355+
const entries = Object.entries(openingHours);
356+
console.log(entries);
357+
358+
// [key, value]
359+
for (const [q, { open, close }] of entries) {
360+
console.log(`On ${q} we open at ${open} and close at ${close}`);
361+
}

0 commit comments

Comments
 (0)