Assign console.log value to a variable

Dru picture Dru · Mar 17, 2013 · Viewed 26.5k times · Source

How can I assign a JavaScript object to a variable which was printed using console.log?

I am in Chrome console. With Ruby I would use test = _ to access the most recent item printed.

Answer

Nick Brady picture Nick Brady · Jan 18, 2017

If you want to do this to an object that has been already logged (one time thing), chrome console offers a good solution.

Hover over the printed object in the console, right click, then click on "Store as Global Variable". Chrome will assign it to a temporary var name for you which you can use in the console.

enter image description here