Photonic
Photonic

Reputation: 1431

Inspecting console.log variables in Chrome

As a thought, i would like to know if is possible to inspect for log properties of any variable in the chrome or any other browsers within the console mode. As i already know that you can already inspect the DOM in inspector element and you can go through debugging mode also. I want to demonstrate my point and why i and most novice would benefit this.

So as you can see in the picture below: enter image description here

So as you can see i am trying to access some element of Array[15] but in the end it always giving me undefined. It nice just to test out some code before recompiling it again which takes time. Plus sometime you don't always knows enough that the function you are calling in JS is compatible with what you trying to achieve.

Upvotes: 0

Views: 3182

Answers (2)

poushy
poushy

Reputation: 1134

You need to add a debugger where you are outputting your array. It seems to me you are trying to access the variable after execution is over, so the variable value is lost, as it goes out of scope. When execution stops at the debugger, you can console.log your variable and properties. At that point the variable will be in scope.

Upvotes: 1

Ranadip Dutta
Ranadip Dutta

Reputation: 9341

Put your entire code inside:

$(document).ready (function (){
    //Paste your code here
});

The whole point is you are trying to access an element in the DOM before it exists.

When your trying to access the class the item doesnot exist.

Alternative: Move your script below the elements in the html.

This is a very generic solution I gave without seeing the code. Request you to post the code as well.

Hope it helps.

Upvotes: 1

Related Questions