I am doing a console.log statement in my javascript in order to log a javascript object. I\'m wondering if there\'s a way, once that\'s done - to copy that object as javascr
This should help stringify deep objects by leaving out recursive Window
and Node
objects.
function stringifyObject(e) {
const obj = {};
for (let k in e) {
obj[k] = e[k];
}
return JSON.stringify(obj, (k, v) => {
if (v instanceof Node) return 'Node';
if (v instanceof Window) return 'Window';
return v;
}, ' ');
}
Using "Store as a Global Variable" works, but it only gets the final instance of the object, and not the moment the object is being logged (since you're likely wanting to compare changes to the object as they happen). To get the object at its exact point in time of being modified, I use this...
function logObject(object) {
console.info(JSON.stringify(object).replace(/,/g, ",\n"));
}
Call it like so...
logObject(puzzle);
You may want to remove the .replace(/./g, ",\n") regex if your data happens to have comma's in it.
Follow the following steps:
JSON.stringify(temp1)
.Right click on data which you want to store
You can now accomplish this in Chrome by right clicking on the object and selecting "Store as Global Variable": http://www.youtube.com/watch?v=qALFiTlVWdg