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:
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.
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/
I think the best way out is by using JSON.stringify()
and passing your data as param:
alert(JSON.stringify(whichIsVisible()));
[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