Starting with the title, I have an initialized object that looks like this
"travellerDetails": {
"traveller_1": {
"Full Name": "",
"Gender": "",
}, "traveller_2": {
"Full Name": "",
"Gender": "",
}, "traveller_3": {
"Full Name": "",
"Gender": ""
}
}
Now, when I retrieve my data object through an Ajax request
"travellerDetails": {
"traveller_1": {
"Full Name": "John Doe",
"Gender": "M",
}, "traveller_2": {
"Full Name": "Jane Doe",
"Gender": "F",
}
},
An issue arises when attempting to save the retrieved data into the initialized object.
bookingForm.travellerDetails = data.travellerDetails;
I expected traveller_3 to remain as "" since I only have 2 travelers in the loaded data. However, it causes an error unless the initialized object matches the same size as the one loaded via Ajax. How can I copy the loaded object into the initialized one despite their different sizes?
Thank you!