Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to interact with the last logged object in Chrome Dev Tools?

If I use console.log to log an object from inside a script, I can see that object in the console, and I can inspect it by clicking the little arrows. So I can see what methods it has (even in its prototype). But is it possible for me to run one of those methods from right there in the console?

In other words, is there some kind of magic variable (similar to $0) that I can type into the console, which will get me the last logged object?

like image 841
callum Avatar asked Nov 15 '12 18:11

callum


2 Answers

You can actually use $_ to get the previously evaluated statement

$$   // Returns an array of elements that match the given CSS selector.
$0   // The currently-selected object in the inspector.
$_   // The previously evaluated statement
$1   // The previously-selected object in the inspector.
$n(index)    // Access to an array of last 5 inspected elements.

For a complete list of everything there is that you can use for all parts of chrome check out the cheatsheet. http://anti-code.com/devtools-cheatsheet/

like image 63
jaredwilli Avatar answered Oct 05 '22 09:10

jaredwilli


There is no such magic variable for objects logged via console.log at the moment. Please file a feature request if you need one: http://webkit.org/new-inspector-bug

like image 27
Yury Semikhatsky Avatar answered Oct 05 '22 09:10

Yury Semikhatsky