У меня ниже json
const data = {
rooms: [
{
roomId: 1,
schedules: [
{ home1: "06:00", dayOfWeek: 1, away: "21:30" },
{ home1: "06:05", dayOfWeek: 2, away: "22:30" }
]
},
{
roomId: 2,
schedules: [
{ home1: "06:00", dayOfWeek: 4, away: "21:30" },
{ home1: "06:05", dayOfWeek: 5, away: "22:30" }
]
}
]
}
Теперь мне нужно добавить вышеперечисленные элементы для dayOfWeek, которых нет в массиве schedules
обоих rooms
Thisэто вывод, который я хочу
const finalOuput = [
//for room 1
{ home1: "00:00", dayOfWeek: 3, away: "02:30", roomId: 1 },
{ home1: "00:00", dayOfWeek: 4, away: "02:30", roomId: 1 },
{ home1: "00:00", dayOfWeek: 5, away: "02:30", roomId: 1 },
{ home1: "00:00", dayOfWeek: 6, away: "02:30", roomId: 1 },
{ home1: "00:00", dayOfWeek: 7, away: "02:30", roomId: 1 },
//for room 2
{ home1: "00:00", dayOfWeek: 1, away: "02:30", roomId: 2 },
{ home1: "00:00", dayOfWeek: 2, away: "02:30", roomId: 2 },
{ home1: "00:00", dayOfWeek: 3, away: "02:30", roomId: 2 },
{ home1: "00:00", dayOfWeek: 6, away: "02:30", roomId: 2 },
{ home1: "00:00", dayOfWeek: 7, away: "02:30", roomId: 2 },
]
Я пробовал перебрать массив rooms
примерно так
const finalOuput = []
rooms.map((room) => {
room.schedules.map((schedule) => {
finalOuput.push(schedule)
})
})
Но не знаю, как проверить dayOfWeek
, которыйотсутствуют в расписаниях rooms
.
Может кто-нибудь помочь, пожалуйста, добиться этого.Спасибо !!!