Skip to content Skip to sidebar Skip to footer

Console.log Not Showing Expected Object Properties

I have the following code in javascript in my node.js application. However certain objects are not stored in my variable appointment. Even if I set them, when I directly access the

Solution 1:

You probably have a Document object instead of a plain object. Those have a custom toJSON method which only yields the properties of your schema and the _id, but nothing else. If you are copying that method with your for-in-loop onto the appointment object, it will get serialized differently as well when logged.

Try

for (var key in appointmentsDB[i].toObject()) {
    appointment[key] = appointmentsDB[i][key];    
}

appointment.test= "res";

console.log(appointment);

Post a Comment for "Console.log Not Showing Expected Object Properties"