2

Out of the following methods, only the last one gives me the object id of the user where I convert the ParseUser to a JSON object then access that. Is there a nicer way to get the objectId?

console.log("GET objectId:" + request.user.get('objectId'));

console.log("objectId:" + request.user.objectId);

console.log("[objectId]: " + request.user["objectId"]);

console.log("toJSON: " + request.user.toJSON().objectId);
Prasad Khode
  • 6,602
  • 11
  • 44
  • 59

2 Answers2

3

to get the user or any other parse object objectId in JavaScript you need to use .id and not .objectId In Parse JavaScript the objectId is saved under id property so you need to change your code to

console.log("GET objectId:" + request.user.id);
Ran Hassid
  • 2,788
  • 1
  • 12
  • 20
0

You can use JSON.parse(request.user) to parse the data and then access properties or items from it. The way I use it is like below.

  var data = JSON.parse(response.data.Message);
   console.log(data.Id) \\Log Id in data object
rinoy
  • 471
  • 4
  • 10
  • Yeah, that is effectively what I do with the last option there (`request.user.toJSON().objectId`), but feels like there must be a nicer way than having to just parse the entire object as JSON first. – Roman Maksymyschyn Oct 11 '16 at 05:28