What does [object Object] mean?

后端 未结 10 2149
醉酒成梦
醉酒成梦 2020-11-22 03:22

I am trying to alert a returned value from a function and I get this in the alert:

[object Object]  

Here is the JavaScript code:



        
10条回答
  •  醉梦人生
    2020-11-22 04:24

    The default conversion from an object to string is "[object Object]".

    As you are dealing with jQuery objects, you might want to do

    alert(whichIsVisible()[0].id);
    

    to print the element's ID.

    As mentioned in the comments, you should use the tools included in browsers like Firefox or Chrome to introspect objects by doing console.log(whichIsVisible()) instead of alert.

    Sidenote: IDs should not start with digits.

提交回复
热议问题