Brad Parks
Brad Parks

Reputation: 71961

Chrome Javascript Console - Reference to object output with console.log(obj)?

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...

Upvotes: 6

Views: 2137

Answers (1)

LJᛃ
LJᛃ

Reputation: 8123

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).

Upvotes: 7

Related Questions