-
-
Save kironroy/a922b694b391554a19f5e8356a4fa336 to your computer and use it in GitHub Desktop.
looping objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const weekDays = ['mon', 'tues', 'wed', 'thu', 'fri', 'sat', 'sun']; | |
const openingHours = { | |
[weekDays[3]]: { | |
open: 12, | |
close: 22, | |
}, | |
fri: { | |
open: 11, | |
close: 23, | |
}, | |
sat: { | |
open: 0, // Open 24 hours | |
close: 24, | |
}, | |
}; | |
// property VALUES | |
const values = Object.values(openingHours); | |
// console.log(values); | |
// entire object | |
const entries = Object.entries(openingHours); | |
// console.log(entries); | |
for (const [key, {open, close}] of entries) { | |
console.log(`On ${key} we open at ${open} and close at ${close}`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment