P粉4589136552023-08-18 09:58:57
As others have pointed out, this is the default serialization of an object. But why is it [object Object]
and not just [object]
?
This is 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 the constructor is called Object
(capital "O"), and the term "object" (lowercase "o") refers to the structural nature of the object.
Usually, when talking about "objects" in Javascript, you actually mean "Object objects", not other types.
Where stringify
should be like this:
function stringify (x) { console.log(Object.prototype.toString.call(x)); }
P粉4652875922023-08-18 09:48:03
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, you should use the tools included in browsers like Firefox or Chrome to inspect objects, instead of using alert
, you can do console.log(whichIsVisible( ))
.
Note: ID should not start with a number.