• Home
  • Blog
  • Contact
  • Book a call

© Copyright 2026 | Vladyslav Dihtiarenko | All Rights Reserved

Quick Tip: Avoid [Object object] in console logs

Mar 6, 2024

•

#javascript

•

1 min read

Have you ever encountered the dreaded [object Object] when logging values to the console? It can be frustrating when you can't see what's actually inside your object. Let me show you a clearer way to log your data.

Instead of logging the object directly, use JSON.stringify() to convert it into a more understandable format.

🔴 The Problem

const yourObject = {
  name: "Alice",
  age: 30,
  skills: ["JavaScript", "React"]
};

console.log("User info:", yourObject);

Console output:

User info: [object Object]

✅ The Simple Fix

Use JSON.stringify() to convert the object to a readable format:

console.log("User info:", JSON.stringify(yourObject));

Console Output:

User info: {"name":"Alice","age":30,"skills":["JavaScript","React"]}

Better! But still a bit hard to read.


✅✅ The Better Fix with Formatting

You can pass null and 2 as the second and third arguments to JSON.stringify() to format the output with indentation:

console.log("User info:\n", JSON.stringify(yourObject, null, 2));

Console Output:

User info:
{
  "name": "Alice",
  "age": 30,
  "skills": [
    "JavaScript",
    "React"
  ]
}

Now that's readable!


🎯 Summary

  • Avoid [object Object] confusion
  • Use JSON.stringify(obj) for quick clarity
  • Use JSON.stringify(obj, null, 2) for beautifully formatted output