Добавил return в map (через forEach так же работает)
const participants = [
{id: 1, name: 'Anakin Skywalker'},
{id: 2, name: 'Padmé Amidala'},
{id: 3, name: 'Luke Skywalker'},
{id: 4, name: 'Princess Leia'},
]
const hotel = [
{
room: [
{id: '', name: ''}
]
},
{
room: [
{id: '', name: ''},
{id: '', name: ''}
]
},
{
room: [
{id: '', name: ''}
]
}
]
const result = hotel.map(h => {
return h.room.map((r) => {
r.id = participants[0].id
r.name = participants[0].name
participants.shift()
return r
})
})
console.log(result)
вот результат
[[{"id":1,"name":"Anakin Skywalker"}],
[{"id":2,"name":"Padmé Amidala"},{"id":3,"name":"Luke Skywalker"}],
[{"id":4,"name":"Princess Leia"}]]