title: How to access length of an array in a json object using javascript in asp.net mvc view
body: <p>I want to access the length of an array in a json object with javascript. I am parsing the List Model of my View in a JSON object and try to access it.
  Here is my function:</p>
  <pre><code>&lt;script&gt;
      function showCerts(storeName) {
          var store = storeName;
          var model = '@Html.Raw(Json.Encode(Model))';
          var obj = JSON.parse(model);
          for (var i = 0; i &lt; Object.keys(obj[store].Certificates).length; i++) {
              var node = document.createElement(&quot;p&quot;);
              var textNode = document.createTextNode(obj[store].Certificates[i].FingerPrint);
              node.appendChild(textNode);
              document.getElementById(&quot;certs&quot;).appendChild(node);
          }
      }
  &lt;/script&gt;
  </code></pre>
  <p>The JSON object looks like this:</p>
  <pre><code>[{&quot;Name&quot;:&quot;ClientAuthIssuer&quot;,&quot;ServerName&quot;:&quot;servername&quot;,&quot;Certificates&quot;:[
  {&quot;id&quot; = 0, &quot;Name&quot; = &quot;CertName&quot;}, 
  {&quot;id&quot; = 1, &quot;Name&quot; = &quot;CertName&quot;}, 
  {&quot;id&quot; = 2, &quot;Name&quot; = &quot;CertName&quot;}]},
  {&quot;Name&quot;:&quot;Disallowed&quot;,&quot;ServerName&quot;:&quot;servername&quot;,&quot;Certificates&quot;:[
  {&quot;id&quot; = 0, &quot;Name&quot; = &quot;CertName&quot;}, 
  {&quot;id&quot; = 1, &quot;Name&quot; = &quot;CertName&quot;}, 
  {&quot;id&quot; = 2, &quot;Name&quot; = &quot;CertName&quot;}]},
  {&quot;Name&quot;:&quot;MY&quot;,&quot;ServerName&quot;:&quot;servername&quot;,&quot;Certificates&quot;:[
  {&quot;id&quot; = 0, &quot;Name&quot; = &quot;CertName&quot;}, 
  {&quot;id&quot; = 1, &quot;Name&quot; = &quot;CertName&quot;}, 
  {&quot;id&quot; = 2, &quot;Name&quot; = &quot;CertName&quot;}]}
  ]
  </code></pre>
  <p>I want to get the length of the Certificates property of ClientAuthIssuer for example to iterate through the certificates in it and add it to a div as a p element.</p>
  <p>I always get this error when trying to run my script:</p>
  <pre><code>Uncaught TypeError: Cannot read property 'Certificates' of undefined
  </code></pre>
  <p>Thank you for your help.</p>