[object Object]
JavaScript Programming Language
Severity: MinorWhat Does This Error Mean?
When JavaScript displays [object Object], it means your code tried to convert a JavaScript object to a string, and JavaScript did it in the most basic way possible. Instead of showing the object's contents, JavaScript just writes its type — [object Object]. This is not really an error — your code keeps running — but it almost always means you are displaying or concatenating something you meant to inspect or format properly. The fix is to use JSON.stringify() to see the contents, or to access the specific property you actually want.
Affected Models
- All browsers
- Node.js
- All JavaScript environments
Common Causes
- Concatenating an object with a string using + instead of accessing a specific property
- Using an object as a template literal value without accessing its properties
- An API or function returned an object but your code treated it as a direct string value
- Using innerHTML or textContent to display an object directly instead of a formatted string
- console.log with string concatenation instead of comma-separated values, which logs objects poorly
How to Fix It
-
To see what is inside the object, use JSON.stringify(yourObject) to convert it to a readable string, or log it with console.log(yourObject) using a comma (not a +) to get the interactive inspector in your browser console.
console.log('Data: ', yourObject) shows the expandable object tree. console.log('Data: ' + yourObject) shows [object Object]. The comma is the key difference.
-
If you want to display a specific piece of data from the object, access the property you need. Instead of displaying the whole object, use yourObject.name or yourObject.message or whichever property holds the value you want to show.
Objects are containers for multiple values. You need to tell JavaScript which specific value inside the container you want — not the whole container.
-
If you need to display the whole object as readable text, use JSON.stringify(yourObject, null, 2). The null and 2 parameters add indentation so the output is nicely formatted.
JSON.stringify with the spacing parameter is the standard way to display an object's full contents as a readable string.
-
Check where the [object Object] appears in your output. Find the line in your code that writes to that location. Look at what variable is being used there and trace back to see what value it actually holds.
Browser DevTools (F12) are your best tool here. Set a breakpoint on the output line and hover over the variable to see its full contents before it gets converted to a string.
-
If you are building a string from an object for display purposes, use a template literal to access specific properties. Example: use the backtick format with dollar-brace syntax to access yourObject.name directly in the string.
Template literals do not prevent [object Object] if you embed a whole object — you still need to access individual properties or call JSON.stringify inside the template.
When to Call a Professional
[object Object] is a very common beginner and intermediate JavaScript issue. No outside help is needed — it is always fixed in your own code. Once you understand when objects auto-convert to strings, you will recognise this immediately.
Frequently Asked Questions
Why does JavaScript show [object Object] instead of the actual contents?
When JavaScript converts an object to a string automatically (for example, when you add it to another string), it calls the object's toString() method. For plain objects, toString() returns '[object Object]' — a generic description of the type. This default behaviour exists for technical reasons, but it is rarely what you actually want. JavaScript does not know which property you care about, so it falls back to this generic output.
I see [object Object] in my webpage. How do I find which line of code is causing it?
Open your browser's developer tools (press F12), go to the Console tab, and look for any logged values. Then search your HTML or JavaScript source for the text that surrounds [object Object] to find where the object is being inserted. Browser DevTools also let you set breakpoints to pause execution and inspect variable values before they reach the page.
Is [object Object] always a mistake or can it appear intentionally?
It almost always indicates a mistake — someone accidentally converting an object to a string. In rare cases, a developer might explicitly call toString() on an object that has a custom toString() method. But plain objects showing [object Object] in user-visible output is virtually always a bug worth fixing.