2

I have an object with deeply nested properties.

Here is the result of console.log(myObject) in Chrome. enter image description here

But the result of console.log(myObject.schedules) is {}.

When I JSON.stringify the original object the result is {"schedules":{}}, which I find really confusing. As you see above, its logging a lot more than just that.

Any idea what the problem is?

3
  • 1
    worth mentioning that the Chrome console for objects is of the object at the time they are opened, not at the time they are logged. so if you are changing your object later (even after logging), by the time you go to open it in the console it will almost certainly be showing you the altered object not the one at time of logging. (i sometimes find i have to JSON.stringify, to see the whole object as it was at time of logging) Commented Dec 9, 2014 at 6:11
  • 1
    can you share myObject Commented Dec 9, 2014 at 6:13
  • @arhoskins Please find the answers below and mark one as accepted whichever solves your problem. Commented Dec 9, 2014 at 6:20

3 Answers 3

4

Do console.dir(myObject) instead.

console.dir() displays an interactive list of the properties of the specified JavaScript object. The output is presented as a hierarchical listing with disclosure triangles that let you see the contents of child objects.

console.dir() | MDN

Sign up to request clarification or add additional context in comments.

6 Comments

Good tip, but this does not actually help with my problem.
@arhoskins Please share your object contents using JSON.stringify() so I can help you further.
@arhoskins What do you get in the console if you do console.dir(myObject) ?
The exact same thing as console.log
@arhoskins It works very well at my end. What browser are you using? As I said earlier, if you could provide me the string that you get on doing JSON.stringify(myObject), I will be able to help you further.
|
1

You can also use JSON.stringify(object), for more details read this.

Comments

0

The problem is that my object was being created via an asynch method call. So, at the point I was console.log() and JSON.stringify(), the object was not done being created.

1 Comment

Then the console.dir(myObject) should be inside the callback of the asynch method call.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.