javascript - console.log not showing expected object properties -


i have following code in javascript in node.js application. objects not stored in variable appointment. if set them, when directly access them works: console.log(appointment.test);

what have done wrong in code?

var appointment = {     subscribed: false,     enoughassis: false,     studentslotsopen: false }; console.log(appointment); (var key in appointmentsdb[i]) {     appointment[key] = appointmentsdb[i][key];     }  appointment.test= "res";  console.log(appointment.test); console.log(appointment); 

and here produced output:

{ 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 as:

{ comment: 'fsadsf',   room: 'dqfa',   reqassi: 3,   maxstud: 20,   timeslot: 8,   week: 31,   year: 2013,   day: 3,   _id: 51f957e1200cb0803f000001,   students: [],   assis: [] } 

the following 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 expect last output provides entries test, subscribed, enoughassis , studentslotsopen. wrong in code?

the solution found manually copy elements wanted to.

you have document object instead of plain object. have custom tojson method yields properties of schema , _id, nothing else. if copying method for-in-loop onto appointment object, serialized differently when logged.

try

for (var key in appointmentsdb[i].toobject()) {     appointment[key] = appointmentsdb[i][key];     }  appointment.test= "res";  console.log(appointment); 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -