All Articles

How to copy an object from the Chrome inspector console as code

Have you ever do console.log an object and wondering how can copy the object over? You have a few options.

Solution 1. Copy, and you are all set!

  1. Right-click to the object, select Store as global variable. Usually, Chrome stored it as temp1
  2. Type copy(temp1)
  3. You can paste now 😆

How to copy an object from the Chrome inspector console as code

Note: If you’re trying to copy a recursive object, you will get [object Object] when pasting. See the solution 2.

Solution 2: Programmatically do JSON.stringify and copy the string 🤪

  1. Right-click to the object, select Store as global variable. Usually, Chrome stored it as temp1
  2. Type copy(JSON.stringify(temp1))
  3. There you have it!

How to copy an object from the Chrome inspector console as code

Bonus: How to copy JSON as TypeScrip type

  1. Install VSCode Paste JSON as Code extension
  2. Follow either solution 1 and 2 to copy the object
  3. Open VSCode, select View -> Command Pallette or press Command + Shift + P
  4. Select Paste JSON as Types
  5. You have the type now. It supports many languages such as C# or Java, not just TypeScript.

How to copy an object from the Chrome inspector console as code

Published 10 Oct 2020

Recent Posts

Apply types to entire function expressions when possible

Consider applying type annotations to entire function expressions, rather than to their parameters and return type. If you're writing the same type signature repeatedly, factor out a function type.

Angular Jira Clone Part 07 - Build a rich text editor

My seventh tutorial will focus on another kind of text editor - a rich text HTML editor


Follow @tuantrungvo on Twitter for more!