In my code, I have an object named roomDetails
that contains various room labels. My goal is to extract the label from this object and then assign it as the value of the roomLabel
property in each item of the patientArray
.
roomDetails = {
room01{label: "Room 1"},
room02{label: "Room 2"},
room03{label: "Room 3"},
room04{label: "Room 4"}
}
let patientArray = [
{ roomLabel: '', name: 'John'},
{ roomLabel: '', name: 'Shawn'},
{ roomLabel: '', name: 'Gereth'},
{ roomLabel: '', name: 'Elminster'}
]
The desired output for the patientArray
should be:
let patientaArray = [
{ roomLabel: 'Room 1', name: 'John'},
{ roomLabel: 'Room 2', name: 'Shawn'},
{ roomLabel: 'Room 3', name: 'Gereth'},
{ roomLabel: 'Room 4', name: 'Elminster'}
]
I've made attempts using JavaScript but encountered issues with overwriting values. Here is part of my existing code:
Object.keys(roomDetails).map((key, index) => {
const roomLabel = roomDetails[key].label;
patientArray.forEach((pi, index) => {
pi.roomLabel = roomDetails[key].label;
});
});
I need assistance in finding a solution that preserves the correct values without overwriting them. Any guidance would be greatly appreciated. Thank you.