Last updated: Mar 7, 2024
Reading time·6 min
The easiest way to copy an object or an array from the Console tab is to:
console.log()
the object or array.Console
tab.Ctrl
+ V
to paste it.I passed the following object to the console.log()
method in the example.
const obj = { id: 1, first: 'bobby', last: 'hadz', salary: 500, address: { country: 'Belgium', city: 'Ghent', }, }; console.log(obj);
Your object or array could be as deeply nested as necessary and this approach works.
Make sure you have selected the Console
tab in your browser's developer tools:
F12
.Console
tab and console.log()
the object.Alternatively, you can copy an object or an array in the Chrome Console tab by storing it as a global variable:
console.log
the object or the array.Console
tab, right-click on the object or array and select Store
as Global Variable.temp1
.copy()
function to copy the object or array to your clipboard, e.g.
copy(temp1)
.copy(temp1)
Here is a short clip that demonstrates how this works.
You can then use Ctrl
+ V
(or Cmd
+ V
on macOS) to paste the copied
object or array.
copy()
method copies the object or array to your clipboard and returns undefined
.If you work with a recursive object or array (one that references itself), you
might get [object Object] when you pass it to the copy()
function.
To resolve the issue, try to pass the object to the
JSON.stringify method before passing it
to the copy()
function.
copy(JSON.stringify(temp1))
If you get the error TypeError: Converting circular structure to JSON, click on the link and follow the instructions.
Another way to copy an object or an array from the Console tab in Chrome is to
define the variable directly in the Console tab and use the copy()
function.
For example, you could paste the following to your Console tab to copy the obj
variable to your clipboard.
const obj = { id: 1, first: 'bobby', last: 'hadz', salary: 500, address: { country: 'Belgium', city: 'Ghent', }, }; copy(obj)
If you need to copy a recursive object or an array, use the JSON.stringify()
method when calling the copy()
function.
const obj = { id: 1, first: 'bobby', last: 'hadz', salary: 500, address: { country: 'Belgium', city: 'Ghent', }, }; copy(JSON.stringify(obj))
The JSON.stringify()
method converts the given object or array to a JSON
string.
If you get the error TypeError: Converting circular structure to JSON, click on the link and follow the instructions.
If you are sending the object or array in an HTTP request (e.g. POST or PUT), you can copy it from the Network tab.
If you need to copy an object or an array from an HTTP response, you could also copy it from the Network tab.
If you don't see the Network tab, click on the >>
icon as shown in the
screenshot and select Network.
Ctrl
+ V
(or Cmd
+ V
) to paste the copied object or array.Here is a short clip that demonstrates how this works.
Make sure the Network tab is selected to be able to view the HTTP requests.
You can also copy the object or array by using the Store object as a global variable option.
If you don't see the Network tab, click on the >>
icon as shown in the
screenshot and select Network.
temp1
.copy()
function to copy the object or array to your clipboard.copy(temp1)
JSON.stringify()
method.copy(JSON.stringify(temp1))
If you get the error TypeError: Converting circular structure to JSON, click on the link and follow the instructions.
You can also copy an object or an array from the Sources tab in Chrome when debugging.
If you don't see the Sources tab, click on the >>
icon and select
Sources from the dropdown menu.
Click on the file in which the object is located in the left sidebar (e.g.
index.js
).
Add a breakpoint right after the object or array you want to copy.
undefined
.You can add a breakpoint by left-clicking on a line number in the code editor to the right.
F5
.Ctrl
+ V
to
paste it.Alternatively, you can right-click on the object in the Scope tab and select Store object as global variable.
Your Console
tab will open and the global variable will have a name similar to
temp1
.
Use the copy()
function to copy the object or array to your clipboard.
copy(temp1)
If you work with recursive objects or arrays, use the JSON.stringify()
method.
copy(JSON.stringify(temp1))
If you get the error TypeError: Converting circular structure to JSON, click on the link and follow the instructions.
I've also written an article on how to edit and replay XHR (HTTP) requests in Chrome and Firefox.
You can learn more about the related topics by checking out the following tutorials: