0

I have the following code to get info from a JSON.

$http.get('http://localhost:3000/folder/'Id)
     .success(function (response) {
           console.log("response ", response);
           console.log("words: ", response.result.all.Word);
     })
     .error(function (response) {
           console.log("error");
     });

But I have a problem to get info in the array:

TypeError: Cannot read property 'all' of undefined

In response I have:

response  [Object, Object]
  0: Object
    _id: "543e95d78drjfn38ed53ec"
     result: Object
       all: ObjectWord: Array[17]
        0: "word1"
        1: "word2"
        2: "word3"
         ...

Thanks for your help!

1
  • response is an array of objects. According to the JSON result object is inside the first array. Try adding an index response[0].result.all Commented Oct 21, 2014 at 8:35

2 Answers 2

1

Your response appears to be an array of 2 objects.

Replace:

console.log("words: ", response.result.all.Word);

With:

for(var i = 0; i < response.length; i++){
    console.log("words: ", response[i].result.all.Word);
}

This should iterate over both objects in the response, and log the related word.

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

5 Comments

Thanks but still have an error "words: undefined" . I have also to iterate with "Words"?
That means that response[i].result.all does not have a property called Word. Try console.log("words: ", response[i].result.all); to see what it does contain.
@Carlos i think it's response[i].result.all[0]
@Carlos was dat for me
Now what does dat mean @Carlos ?
0

You are missing index, try the below code:

response[i].result.all[j]   where j=0....n

1 Comment

U r not txtng. Please don't write like that.

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.