{ "questions": [
{
"text": "Which colors do you see in the rainbow?",
"answer": "A",
"A": "RED",
"B": "ORANGE",
"C": "YELLOW",
"D": "GREEN"
},
{
"text": "What is sanatbek's family name?",
"answer": "C",
"A": "Saidov",
"B": "Muhammadlatipov",
"C": "Matlatipov",
"D": "Boboyev"
},
{
"text": "How many members does this company have?",
"answer": "C",
"A": "3",
"B": "8",
"C": "9",
"D": "2"
}
]
}
This is my JSON file and I need to get length of questions in AngularJS like this:
function getQuestionCount() {
return $scope.questions.length;
}
Here $scope.questions is declared in the controller:
I have tried several solutions like
return Object.keys($scope.questions).lengththis isreturning value: 6; after displayingconsole.log($scope.questions). I understood that this was number of properties of my Parsed Object.- Then after thinking a bit, I tried this
return $scope.questions.data.questions.length;this is working. However, Following error is showing on my console.
Here is My Error Message:

TypeError: Cannot read property 'data' of undefined.
$scope.questions? Is it the array of three objects?questionskey. Mr Raghu's solution is the answer for my problem.