How to show full object in Chrome console?

前端 未结 9 1293
情话喂你
情话喂你 2020-11-28 02:04
var functor=function(){
    //test
}

functor.prop=1;

console.log(functor);

this only show the function part of the functor, cannot show the prope

9条回答
  •  孤独总比滥情好
    2020-11-28 02:24

    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));
    

提交回复
热议问题