Skip to content
Advertisement

Mapping array with objects of open hours in react

So Im trying to render in jsx a list of 7 days with open hours, taking data from my json file. I want to make it looks somehow like this:

Mon 09:00 – 21:00

Tue 09:00 – 21:00

Wed 09:00 – 21:00

Thu 09:00 – 21:00

Fri 09:00 – 21:00

Sat 11:00 – 21:00

Sun 11:00 – 21:00

In my json file it looks like this:

JavaScript

So i tried to map openHours, got 2 objects, but when I try to map those 2 objects I get error that map is not a function. I wanted it to map in this way, that in this case, it returns 5 items with 09:00-21:00 and 2 items 11:00-21:00, but there can be case, that openHours will containt 3 objects, like days 1-5, day 6 and day 0. Is there any way to do it?

Advertisement

Answer

You should be able to iterate over openHours and then, within that loop, iterate over days.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement