JavaScript - How do I access a value in an array, containing an object that contains and array of objects?? I need a property of one of the objects [duplicate]
Examining objects via console.log
happens in an asynchronous manner. The console receives a reference to the object synchronously, but does not display the properties of the object until it is expanded (in some cases, depending on the browser and whether you have dev tools open when the log happens). If the object has been modified before examining it in the console, the data shown will have the updated values.
For example, Chrome will show a little i
in a box which, when hovered, says:
Object value at left was snapshotted when logged, value below was evaluated just now.
to let you know what you're looking at.
One trick for logging in these cases is to log the individual values:
console.log(obj.foo, obj.bar, obj.baz);
Or JSON encode the object reference:
console.log(JSON.stringify(obj));
Redefining console.log
will solve the problem.
var originalLog = console.log;
console.log = function(obj) {
originalLog(JSON.parse(JSON.stringify(obj)));
};