Skip to content

Instantly share code, notes, and snippets.

@nicbou
Created September 16, 2016 11:05
Show Gist options
  • Save nicbou/8bbe7cc08744995c77d65f04b91e98c4 to your computer and use it in GitHub Desktop.
Save nicbou/8bbe7cc08744995c77d65f04b91e98c4 to your computer and use it in GitHub Desktop.
Pretty print JavaScript objects in Chrome Developer Tools
// Paste this in your console
Object.prototype.export=function(){e=JSON.stringify(this,0,2).replace(/\"([^(\")"]+)\":/g,"$1:");copy(e);console.log(e);console.warn('Copied to clipboard') };
// Then do this for any object you want to copy
myObject.export();
// And you will get a nicely formatted version of your object in the clipboard,
// properly spaced, without the properties wrapped in quotes.
const myObject = {a: 1, b: 'bee', c: [1,2,3]};
myObject.export()
> {
> a: 1,
> b: "bee",
> c: [
> 1,
> 2,
> 3
> ]
> }
> Copied to clipboard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment