0

I have the following JSON:

at http://localhost:3000/folder/1234567

[

   {

      "_id": "543e95d78a1cec2a38ed53ec"

   },

   {

      "_id": "543e95d78a1cec2a38ed53f1"

   }

]

And I want to get all the _id.

So, I am doing something like:

$http.get('http://localhost:3000/folder/' + folderId)
                        .success(function (response) {
                    console.log("response"+ response);
                    console.log("response id"+ response.id);

But I have:

response [object Object],[object Object]
response id undefined 

How can I fix to get the _id ?

Thanks for your help !

3
  • The response is an Array so you have to loop over it. Which _id do you need? Commented Oct 17, 2014 at 8:17
  • How can I proceed with an Array? All the _ids. Thanks! Commented Oct 17, 2014 at 8:19
  • it depends what you want to do with your data. if you want to display them, just put the data to your scope and use ng-repeat in your view. or if you want to do something else, you can use angulars foreach or so. Commented Oct 17, 2014 at 8:25

1 Answer 1

2

To get all the Ids in reverse order:

var allIds = [];

$http.get('http://localhost:3000/folder/' + folderId).success(function(res) {
    for (var i = res.length-1; i>-1; i--) {
        allIds.push(res[i]._id);
    }
    // this prints an array with all the Ids 
    console.log(allIds);
});
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.