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 an array, which I used push method:

            for(var j=0; j<$scope.currentUsers.length; j++){
            $scope.Users.push({user_id:$scope.currentUsers[j].user_id, student_name:$scope.currentUsers[j].student_name, 
                "A":[{"color":"white"}, {count:0}], 
                "E":[{"color":"white"}, {count:0}],
                "J":[{"color":"white"}, {count:0}]
            });

        }

I am wondering how i can access to the count in A, E or J?

I tried $scope.Users[i].A.count

or I tried $scope.Users[i][A][count]

They all showd me "NaN" or undefined. Am i doing something wrong?

Thanks in advance for your help!

share|improve this question
up vote 2 down vote accepted

The "A" field is an array. So, the right piece of code is :

$scope.Users[i].A[1].count

Otherwise, declare each of the fields "A","E","J" as JSON objects with :

"A":{"color":"white", count:0}, 
"E":{"color":"white", count:0},
"J":{"color":"white", count:0}

and access them with :

$scope.Users[i].A.count
share|improve this answer
    
Thank you! now it is clear! – Lisa Apr 5 '15 at 23:35

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.