Assign console.log value to a variable

后端 未结 5 761
青春惊慌失措
青春惊慌失措 2020-12-25 13:56

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 = _

5条回答
  •  情书的邮戳
    2020-12-25 14:32

    Here is chrome reference for comand line api. There is $_ variable but it "Returns the value of the most recently evaluated expression" not printed, you can make your own log function like this:

    function log(data){
       console.log(data);
       return data;
    }
    // after that you can access last printed value by $_
    

    Please, note that my function is for example, console.log possibilities is much more advanced

提交回复
热议问题