Javascript / Chrome - How to copy an object from the webkit inspector as code

后端 未结 11 1906
天涯浪人
天涯浪人 2020-11-29 14:47

I am doing a console.log statement in my javascript in order to log a javascript object. I\'m wondering if there\'s a way, once that\'s done - to copy that object as javascr

11条回答
  •  自闭症患者
    2020-11-29 15:11

    Follow the following steps:

    1. Output the object with console.log from your code, like so: console.log(myObject)
    2. Right click on the object and click "Store as Global Object". Chrome would print the name of the variable at this point. Let's assume it's called "temp1".
    3. In the console, type: JSON.stringify(temp1).
    4. At this point you will see the entire JSON object as a string that you can copy/paste.
    5. You can use online tools like http://www.jsoneditoronline.org/ to prettify your string at this point.

提交回复
热议问题