Isaac
Isaac

Reputation: 217

How can I access and queried object's id using Parse?

I'm trying to get the id of a queried object, how can I do this?

My query:

var query = new Parse.Query(Parse.User);
query.equalTo("username", "user1"); 
query.find({
  success: function(item) {
        console.log(item) // This works
        console.log(item.id) // This is undefined
  }
});

My returned data resembles this in the console:

> f 
  > createdAt : "May 28"
  > _serverData:
    > username: "user1"
    > email: "[email protected]"
  > id: "93jcdn19"

How can I access the id within my javascript code? Thanks.

Upvotes: 1

Views: 101

Answers (1)

Matthew Arkin
Matthew Arkin

Reputation: 4648

I believe that returns an array, so you would do console.log(item[0].id)

To print out every object's id you would do something like

for (var index = 0; index < item.length; index++){
    console.log(item[index].id)
}

Upvotes: 2

Related Questions