6

Is there a way to get a javascript reference to an object that was output to the chrome console?

For example, say I had the following javascript:

top.it = {hi:'there'};
console.log(top.it);

This would output to the chrome console as

Object {hi: "there"} 

I do this alot, and sometimes would like to get a reference to the object in the console, to run methods on it, and things like that.

Is there a way to get a reference to objects that have been output using console.log?

I know there's a way to get references to recently inspected items (e.g. $0), but this isn't for inspected items...

2
  • I generally just set breakpoints so I can access the variables from the console debugger. Commented Sep 4, 2014 at 0:11
  • yeah i do that too - but that's when I'm thinking ahead ;-) Sometimes during development I leave in lots of console.log(...) statements, and would like to jump in and work with something... Commented Sep 4, 2014 at 1:07

1 Answer 1

7

Right-click on the console log output and choose the option "Store as Global Variable". The console will display the name of the variable it has been saved to, such as temp1, temp2, etc. which you can then refer to in console commands.

Here is a video of it (not created by me).

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

Comments

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.