Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does [object Object] mean? (JavaScript)

One of my alerts is giving the following result:

[object Object]  

What does this mean exactly? (This was an alert of some jQuery object.)

like image 838
Sriram Avatar asked Jan 17 '12 09:01

Sriram


People also ask

Why do I get object object?

To answer your question, what this means is that you are alerting an instance of an object. For instance, when alerting the object, toString() is called on the object, and the default implementation returns [object Object]. If you want to inspect the object, you should either console. log it, JSON.

What is object object in console?

object Object] is a string representation of an object. You may see this text if you use alert() to print an object to the screen, for instance. You can view the contents of an object using console.15-Dec-2020.

What is object object react?

While working with state variables in React, you might run into an error stating Tried to merge an object, instead got [object Object] . This usually happens when you are directly modifying your state and altering its original structure incorrectly.


1 Answers

It means you are alerting an instance of an object. When alerting the object, toString() is called on the object, and the default implementation returns [object Object].

var objA = {}; var objB = new Object; var objC = {};  objC.toString = function () { return "objC" };  alert(objA); // [object Object] alert(objB); // [object Object] alert(objC); // objC 

If you want to inspect the object, you should either console.log it, JSON.stringify() it, or enumerate over it's properties and inspect them individually using for in.

like image 160
Matt Avatar answered Oct 04 '22 15:10

Matt