Wanna see something cool? Check out Angular Spotify 🎧

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

Read more

 — Use async functions instead of callbacks for asynchronous code
 — The different between type and interface in TypeScript
 — Angular Jira Clone Part 06 - Build a markdown text editor
 — Apply types to entire function expressions when possible
 — Angular Jira Clone Part 05 - Build an interactive drag and drop board

Follow @trungvose on Twitter for more!