1

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!

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

Comments

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.