I have the following code in javascript in my node.js. application However, some objects are not stored in my appointment variable. Even if I install them when I directly access them, it works: console.log(appointment.test);
What have I done wrong in this code?
var appointment = { subscribed: false, enoughAssis: false, studentSlotsOpen: false }; console.log(appointment); for (var key in appointmentsDB[i]) { appointment[key] = appointmentsDB[i][key]; } appointment.test= "res"; console.log(appointment.test); console.log(appointment);
And here is the result:
{ subscribed: false, enoughAssis: false, studentSlotsOpen: false } res { comment: 'fsadsf', room: 'dqfa', reqAssi: 3, maxStud: 20, timeSlot: 8, week: 31, year: 2013, day: 3, _id: 51f957e1200cb0803f000001, students: [], assis: [] }
The variable console.log(appointmentsDB[i]) looks like this:
{ comment: 'fsadsf', room: 'dqfa', reqAssi: 3, maxStud: 20, timeSlot: 8, week: 31, year: 2013, day: 3, _id: 51f957e1200cb0803f000001, students: [], assis: [] }
Next command:
console.log(Object.getOwnPropertyNames(appointmentsDB[i]), Object.getOwnPropertyNames(Object.getPrototypeOf(appointmentsDB[i])));
Shows:
[ '_activePaths', '_events', 'errors', '_maxListeners', '_selected', '_saveError', '_posts', 'save', '_pres', '_validationError', '_strictMode', 'isNew', '_doc', '_shardval' ] [ 'assis', 'timeSlot', 'db', '_schema', 'id', 'base', 'day', 'collection', 'reqAssi', 'constructor', 'comment', 'year', 'room', 'students', 'week', '_id', 'maxStud' ]
However, I would expect my last output to also provide the test, signed, enoughAssis and studentSlotsOpen entries. What is wrong with this code?
The solution I found was to manually copy the elements that I wanted.