DEV Community

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

Posted on • Edited 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 😄

Top comments (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 • Edited

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

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

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

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

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

Glad I could help!

Collapse
 
rammohan222 profile image
RamMohan

Definitely It will reduce my frustration while I'm debugging the code 👌