Join the Stack Overflow Community
Stack Overflow is a community of 6.5 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I have the 2 following JSON:

[
  "36Yhfdjrnbfkdjres984",
  "53673hifujhdjkhgk77",
  "3456duedhde84473"
]

and

[
   {"_id":"36Yhfdjrnbfkdjres984"},
   {"_id":"53673hifujhdjkhgk77"},
   {"_id":"3456duedhde84473"}
]

I need to parse both with 2 differents methods:

$scope.onClickItem = function(tag) {
        $http.get('http://localhost:5000/api1')
             .success(function (response) {
                    console.log("response ", response);
             })
             .error(function (response) {
                     console.log(response);
             });
};

In response, I can see corectly the right JSON I need to get the id for /api1 and /api2

share|improve this question
    
im not sure what the question is.. – Pogrindis Oct 21 '14 at 14:45
    
in response, I can see the JSON (I have 1 method for each of them) but I would like to store the id in an array. – Carlos Oct 21 '14 at 14:46
    
these are separate responses. I just put 1 method here for the example. – Carlos Oct 21 '14 at 14:48
up vote 0 down vote accepted

Saving the Id's to an array..

Create the Array object :

$scope.IdArray = [];

Then when you run through your function you can push the id into this.

$scope.onClickItem = function(tag) {
        $http.get('http://localhost:5000/api1')
                        .success(function (response) {
                            console.log("response ", response);
                            $scope.IdArray.push(response._id);
                        })
                        .error(function (response) {
                            console.log(response);
                        });
    };

Might be nicer to push an object into the array so something along the lines :

var idObj = {"ID", response._id};
$scope.IdArray.push(idObj);

But its all up to you and how you want to work with it.

Then you can do what you like with the ID array.

share|improve this answer
    
thanks but I already tried and I have undefined for response._id – Carlos Oct 21 '14 at 14:52
    
well then your response does not have an id :) I suspect you will need response.$each(function(singleItem){$scope.IdArray.push(sing‌​leIte._Id);}); – Pogrindis Oct 21 '14 at 14:54
    
Is it mandatory to use JQuery? – Carlos Oct 21 '14 at 15:08
1  
its NEVER mandatory to use jQuery... Just longer to type.. – Pogrindis Oct 21 '14 at 15:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.