0

I know how to iterate over an object by destructing it in the 'for-of loop' which I consider an easy method:

let cafeHours = {
    thurs: {
      open: '11:00 am',
      close: '11:00 pm',
    },
    fri: {
      open: '10:00 am',
      close: '11:00 am',
    },
    satur: {
      open: '8:00 am',
      close: '11:00 pm',
    }, 
};

let hours = Object.entries(cafeHours);

for (let [day, {open, close}] of hours) {
  console.log(`On ${day}day we open at ${open} and close at ${close}`);
};


I was wondering whether I can iterate over this object and it's objects using a Normal for loop which contains 3 statements which is like this? (and get the above result)

for (let i = 0; i<hours.length; i++){
    
};

Please tell me if I'm complicating stuff but I get really curious sometimes

Sigi
  • 1
  • 1

0 Answers0