How to show full object in Chrome console?

JavascriptDebuggingGoogle Chrome

Javascript Problem Overview


var functor=function(){
	//test
}

functor.prop=1;

console.log(functor);

this only show the function part of the functor, cannot show the properties of the functor in console.

Javascript Solutions


Solution 1 - Javascript

Use console.dir() to output a browse-able object you can click through instead of the .toString() version, like this:

console.dir(functor);

> Prints a JavaScript representation of the specified object. If the object being logged is an HTML element, then the properties of its DOM representation are printed [1]


[1] https://developers.google.com/web/tools/chrome-devtools/debug/console/console-reference#dir

Solution 2 - Javascript

You might get better results if you try:

console.log(JSON.stringify(functor));

Solution 3 - Javascript

You might get even better results if you try:

console.log(JSON.stringify(obj, null, 4));

Solution 4 - Javascript

var gandalf = {
  "real name": "Gandalf",
  "age (est)": 11000,
  "race": "Maia",
  "haveRetirementPlan": true,
  "aliases": [
    "Greyhame",
    "Stormcrow",
    "Mithrandir",
    "Gandalf the Grey",
    "Gandalf the White"
  ]
};
//to console log object, we cannot use console.log("Object gandalf: " + gandalf);
console.log("Object gandalf: ");
//this will show object gandalf ONLY in Google Chrome NOT in IE
console.log(gandalf);
//this will show object gandalf IN ALL BROWSERS!
console.log(JSON.stringify(gandalf));
//this will show object gandalf IN ALL BROWSERS! with beautiful indent
console.log(JSON.stringify(gandalf, null, 4));

Solution 5 - Javascript

this worked perfectly for me:

for(a in array)console.log(array[a])

you can extract any array created in console for find/replace cleanup and posterior usage of this data extracted

Solution 6 - Javascript

I made a function of the Trident D'Gao answer.

function print(obj) {
  console.log(JSON.stringify(obj, null, 4));
}

How to use it

print(obj);

Solution 7 - Javascript

I wrote a function to conveniently print things to the console.

// function for debugging stuff
function print(...x) {
    console.log(JSON.stringify(x,null,4));
}

// how to call it
let obj = { a: 1, b: [2,3] };
print('hello',123,obj);

will output in console:

[    "hello",    123,    {        "a": 1,        "b": [            2,            3        ]
    }
]

Solution 8 - Javascript

With modern browsers, console.log(functor) works perfectly (behaves the same was a console.dir).

Solution 9 - Javascript

To output obj:

console.log(obj, null, 4)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionlovespringView Question on Stackoverflow
Solution 1 - JavascriptNick CraverView Answer on Stackoverflow
Solution 2 - JavascriptBastiBenView Answer on Stackoverflow
Solution 3 - JavascriptTrident D'GaoView Answer on Stackoverflow
Solution 4 - JavascriptKean AmaralView Answer on Stackoverflow
Solution 5 - JavascriptdomSurgeonView Answer on Stackoverflow
Solution 6 - JavascriptJens TörnellView Answer on Stackoverflow
Solution 7 - JavascriptJohn HenckelView Answer on Stackoverflow
Solution 8 - JavascriptakimView Answer on Stackoverflow
Solution 9 - JavascriptKulakov SergView Answer on Stackoverflow