0

I have nested arrays that contain objects, and I am experiencing a really strange problem. The object value I am trying to retrieve is returning "undefined" even though I can see it in the Firefox debugger.

This is my code:

angular.forEach(pages, function(page, pageIndex){

    angular.forEach(page, function(controlObject,controlObjectIndex){

        /* GET THE KEY OF THE OBJECT */
        var keys = [];
        for(var k in controlObject) keys.push(k);

        console.log("CONTROL: "+keys+"  VALUE: "+controlObject.value);  // THIS OUTPUTS:  CONTROL: 01  VALUE: undefined
    });

});

Printscreen of the Firefox console showing that the object parameter is defined

I have search for other people experiencing this problem, and all the quesiton I could found were caused by an AJAX request not completing before trying to access the object, but I do not have any AJAX requests in my code.

I would really appreciate any suggestions! TIA!

Ronny vdb
  • 2,324
  • 5
  • 32
  • 74
  • 1
    You'll have to give us more context. Can we see the statement that logs the whole Array to the console? It's difficult to see how the variables correspond to the values in the console output. – Greg Burghardt Nov 05 '14 at 16:28
  • 1
    Um, that the loop over the properties of your object does only find `01` suggests that your `controlObject` does indeed not have a `value` property?! – Bergi Nov 05 '14 at 16:29
  • 1
    In fact, you need to use `controlObject["01"].value` - the `value` property is on the object a level deeper than you thought. – Bergi Nov 05 '14 at 16:31
  • @Bergi that solved it! I used the following code to access the parameter: controlObject[keys].value. Please change your last comment to an answer so I can accept it. Thanks again! – Ronny vdb Nov 05 '14 at 16:38
  • No! `keys` is an array, it worked only by luck. It should be `controlObject[keys[0]].value` if at all – Bergi Nov 05 '14 at 18:51

0 Answers0