Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assign console.log value to a variable

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.

like image 515
Dru Avatar asked Mar 17 '13 14:03

Dru


People also ask

How do you assign a console log to a variable?

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.

How do I use console log code?

console. log() is used as a debugging tool to help you understand what your code is doing. By displaying a message containing either descriptive text that tells you what is happening or the value of particular variables, you can follow along as your code executes. The user of your app will not see the console.

What is the use of log () in console log ()?

log() The console. log() method outputs a message to the web console. The message may be a single string (with optional substitution values), or it may be any one or more JavaScript objects.


1 Answers

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

like image 57
Nick Brady Avatar answered Sep 19 '22 09:09

Nick Brady