So I have two array of JSON objects, rooms, and reservations. I want to output a new array of objects that has data combined from both those arrays with a new data type. Not sure how to create that new data type.
var rooms = [
{id:1, room:'treehouse'},
{id:2, room:'casa'},
{id:3, room:'vacation'},
{id:4, room:'presidential'}
];
var reservations = [
{id:1, roomID:'2', time:'2pm', location:'rome'},
{id:2, roomID:'3', time:'4pm', location:'paris'},
{id:3, roomID:'1', time:'4pm', location:'london'},
{id:4, roomID:'2', time:'7pm', location:'rome'},
{id:5, roomID:'1', time:'12pm', location:'london'},
{id:6, roomID:'4', time:'4pm', location:'berlin'}
];
Desired Output:
var bookings = [
{id: 1, roomid:1, time:'12pm',location:'london', roomname:'treehouse'},
{id: 2, roomid:1, time:'4pm', location:'london', roomname:'treehouse'},
{id: 3, roomid:2, time:'2pm', location:'rome', roomname:'casa'},
{id: 4, roomid:2, time:'7pm', location:'rome', roomname:'casa'},
{id: 5, roomid:3, time:'4pm', location:'paris', roomname:'vacation'},
{id: 6, roomid:4, time:'4pm', location:'berlin', roomname:'presidential'}
]
I am confused on the logic on how to do this. I was thinking of iterating over the reservations array and for each reservation grab roomId and check in a map structure of rooms and then output. I'm not quite sure what to do.
roomidvsroomID? and why is the type different one is a number, one is a string.