P粉8183174102023-08-21 12:37:52
As others have pointed out, this is the default serialization of objects. But why is it [object Object]
and not just [object]
?
That's because there are different types of objects in Javascript!
stringify(function (){})
-> [object Function]
stringify([])
-> [object Array]
stringify(/x/)
-> [object RegExp]
stringify(new Date)
-> [object Date]
stringify({})
-> [object Object]
This is because constructors are called Object
(capital "O"), and the term "object" (lowercase "o") refers to the structural nature of things.
Usually, when you talk about "objects" in Javascript, you actually mean "ObjectObject", not other types.
Where stringify
should be like this:
function stringify (x) { console.log(Object.prototype.toString.call(x)); }
P粉6114563092023-08-21 11:12:52
The default result of converting an object to a string is "[object Object]"
.
Since you are dealing with jQuery objects, you may want to do the following
alert(whichIsVisible()[0].id);
To print the ID of the element.
As mentioned in the comments, instead of using alert
, you should use tools included in browsers like Firefox or Chrome to inspect objects by doing console.log(whichIsVisible ())
.
Note: ID should not start with a number.