How to output a JavaScript object to console and to page: complete guide
Hello everyone! I just started learning JavaScript and encountered a problem. When I try to output an object to the console using console.log(), I see something like [object Object]. For example:\n\n```javascript\nlet user = {\n name: "Anna",\n age: 25,\n isAdmin: true\n};\n\nconsole.log(user); // Outputs: [object Object]\n```\n\nI want to see the contents of the object: name, age, etc. How can I do this? I tried simply outputting the object to the page via document.write() — the result is the same.\n\nI also need to output the object into an HTML element, for example a div. I tried this:\n\n```javascript\ndocument.getElementById('output').innerHTML = user;\n```\n\nBut the div shows the text "[object Object]".\n\nPlease tell me how to correctly display an object in the console and on a web page? Is there a difference