What does [object Object] mean?

后端 未结 10 2019
醉酒成梦
醉酒成梦 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.

    0 讨论(0)
  • 2020-11-22 04:27

    You can see value inside [object Object] like this

    Alert.alert(  JSON.stringify(userDate)  );
    

    Try like this

        realm.write(() => {
           const userFormData = realm.create('User',{
           user_email: value.username,
           user_password: value.password,
          });
         });
    
          const userDate = realm.objects('User').filtered('user_email == $0', value.username.toString(), );
          Alert.alert(  JSON.stringify(userDate)  );
    

    reference

    https://off.tokyo/blog/react-native-object-object/

    0 讨论(0)
  • 2020-11-22 04:27

    I think the best way out is by using JSON.stringify() and passing your data as param:

    alert(JSON.stringify(whichIsVisible()));
    
    0 讨论(0)
  • 2020-11-22 04:29

    [object Object] is the default string representation of a JavaScript Object. It is what you'll get if you run this code:

    alert({}); // [object Object]
    

    You can change the default representation by overriding the toString method like so:

    var o = {toString: function(){ return "foo" }};
    alert(o); // foo
    
    0 讨论(0)
提交回复
热议问题