arhoskins
arhoskins

Reputation: 373

Javascript: view object in console

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?

Upvotes: 2

Views: 590

Answers (3)

arhoskins
arhoskins

Reputation: 373

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.

Upvotes: 0

Mahesh.D
Mahesh.D

Reputation: 1689

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

Upvotes: 1

Rahul Desai
Rahul Desai

Reputation: 15501

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

Upvotes: 4

Related Questions