1

I have a backend on Parse.com. I am trying to get a value from a User object in javascript cloud code, but it is not working. Let's say I am trying to get the email.

Here is the cloud code that retrieves a User Object...

var printUser = function(){

var query = new Parse.Query(Parse.User);
query.get( "2FSYI1hoJ8");  
query.find({
  success: function(result) {

    console.log(result);
  }
});
};

and here is the result of that search...

I2014-03-07T22:43:21.894Z] [{"email":"[email protected]","phoneVerified":true,"randomNumber":99862,"toPhone":"+13035551212","username":"a","objectId":"2FSYI1hoJ8","createdAt":"2014-03-02T21:07:02.192Z","updatedAt":"2014-03-07T22:43:13.103Z","__type":"Object","className":"_User"}]

So I know the search works. I tried using 'result.get("email")', 'result.email', 'result("email")' and any variation I could find in their documentation to get the email value, but nothing works.

The error codes vary based on what is being called, so I will spare you that.

What am I missing?

1 Answer 1

2

You have an array of objects (with only one element), not a standalone object. The first element in your array is your result object:

result[0].email

will get you the email property of that object.

Sign up to request clarification or add additional context in comments.

2 Comments

Very close... because it is Parse.com, turns out it needed to be result[0].get("email"). Thank you very much! (another day of too much time spent because I am missing the details...)
For future reference, if you only expect a single result you can use query.first() which will prevent this issue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.