title: Getting length of JSON in angular
body: <pre><code>{ "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"
   }
   ]
  }
  </code></pre>
  
  <p>This is my <code>JSON</code> file and I need to get length of questions in <code>AngularJS</code> like this:</p>
  
  <pre><code>function getQuestionCount() {
      return $scope.questions.length;
  }
  </code></pre>
  
  <p>Here <code>$scope.questions</code> is declared in the controller:
  I have tried several solutions like</p>
  
  <ol>
  <li><code>return Object.keys($scope.questions).length</code>  this is <code>returning value: 6</code>; after displaying    <code>console.log($scope.questions)</code> . I understood that this was number of properties of my Parsed Object.</li>
  <li>Then after thinking a bit,  I tried this  <code>return $scope.questions.data.questions.length;</code> this is working. However, Following error is showing on my console.   </li>
  </ol>
  
  <p>Here is My Error Message: </p>
  
  <p><img src="https://i.stack.imgur.com/chCQe.png" alt="Error message"></p>
  
  <pre><code>TypeError: Cannot read property 'data' of undefined.
  </code></pre>