DEV Community

Cover image for How to Copy a Big Object or Array From Console to Clipboard
Vitor Paladini
Vitor Paladini

Posted on • Updated on • Originally published at paladini.dev

How to Copy a Big Object or Array From Console to Clipboard

Have you ever found yourself trying to Ctrl-C a console.log() output, only to get mad when it doesn't really work with long Objects and Arrays?

Gif showing a failed attempt to copy a big object

Here's what you should do instead:

1 - Right-click the console.log() output
2 - Click "Store as global variable"
3 - Run copy(temp1)
4 - Ctrl-V it wherever you want

Gif showing how to copy a long object

Success! You may find that useful when debugging complex data structures or request payloads.

Let me know in the comments what else copy() might be useful for! ๐Ÿ˜„


Cover photo by Paolo Nicolello on Unsplash

Why the cover photo is a monkey? Well, I make the same face when I'm debugging.


Hey, let's connect ๐Ÿ‘‹

Follow me on Twitter and let me know you liked this article!

And if you really liked it, make sure to share it with your friends, that'll help me a lot ๐Ÿ˜„

Discussion (15)

Collapse
lionelrowe profile image
lionel-rowe

Awesome tip, I never knew about copy before! In your example, you don't need to Store as global variable though โ€” you could just copy(bigObject) directly.

Collapse
vtrpldn profile image
Vitor Paladini Author • Edited on

You're right! I've created bigObject so I could simulate something like:

fetch('http://example.com/movies.json')
  .then(response => response.json())
  .then(data => console.log(data.bigObject));

but I'm glad you caught that ๐Ÿ˜„

Collapse
cloudpower97 profile image
Claudio Cortese

Nice tip, never heard of copy before!

Collapse
bravemaster619 profile image
bravemaster619

Good tip! My hack was this:

JSON.stringify(temp1);
Enter fullscreen mode Exit fullscreen mode

with Command C, V.

Very uncomfortable compared to copy method

Collapse
____marcell profile image
Marcell Cruz

Great tip, but I think the gifs are a little bit too fast

Collapse
vtrpldn profile image
Vitor Paladini Author

Thanks for feedback, Marcell. I thought that would be the case...

I speed them up to decrease the overall frame count making each gif lighter, but I agree that it is looking a little intense ๐Ÿ˜ฌ

I'll fix them and update the post, thanks!

Collapse
jonrandy profile image
Jon Randy • Edited on

Or just use Firefox, right click and 'Copy object'. Firefox's dev tools really are better than Chrome's IMO

Collapse
madza profile image
Madza

A neat little trick that could come in handy at times ๐Ÿ”ฅ๐Ÿ‘

Collapse
vtrpldn profile image
Vitor Paladini Author

I'm stealing "neat little trick" for the name of this series, thanks ๐Ÿ˜„

Collapse
madza profile image
Madza

I feel a lot of ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ coming in the future! ๐Ÿ’ฏ

Collapse
amegabosco profile image
amegabosco

Amazing ! Can you please share the tool used to generate the gif capture ?

Collapse
vtrpldn profile image
Vitor Paladini Author

Of course! I've used Kap for capturing it and Gif Brewery for optimizing it and making it faster ๐Ÿ˜„

Collapse
abdisalan_js profile image
Abdisalan

Very useful! Thanks ๐Ÿ‘๐Ÿพ

Collapse
vtrpldn profile image
Vitor Paladini Author

Glad I could help!

Collapse
rammohan222 profile image
RamMohan

Definitely It will reduce my frustration while I'm debugging the code ๐Ÿ‘Œ