One of my alerts is giving the following result:
[object Object]
What does this mean exactly? (This was an alert of some jQuery object.)
Advertisement
Answer
It means you are alerting an instance of an object. When alert
ing 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
.