title: Why Uncaught TypeError: Cannot read property 'length' of undefined?
body: <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;meta charset="utf-8"&gt;
          &lt;script src="dist/localforage.js"&gt;&lt;/script&gt;
          &lt;script type="text/javascript"&gt;
          "use strict"
          var value1;
          var $id = function(id) { return document.getElementById(id); }
          var certArr;        
          window.onload = function()
          {
              $id("read-button").addEventListener("change", onChangeFile, false);
          };      
          function onChangeFile(e) {
              alert("aaaaddffd");
              var file = e.target.files[0];
              var reader = new FileReader();
              reader.onload = function(e) {
                  var Oribuf = e.target.result;
                  var certArr = new Uint8Array(Oribuf);
                  alert(certArr);
              };      
              reader.readAsArrayBuffer(file);     
              alert("aaaa: " + certArr);
              readFile(certArr);
          };      
          function readFile(arrData) {
              // Here. Why this alert Undefined?
              alert("bbbbb: " +arrData);                      
              var key = 'STORE_KEY';
              var r = document.getElementById('results');     
              localforage.setItem('cert1', 1234688, function(err, value) {
                  r.innerHTML += 'Saved: ' + value + '&lt;br /&gt;';
              });     
              localforage.getItem('cert1', function(err, value) {
                  // console.log(value);
                  r.innerHTML += 'Read: ' + value + '&lt;br /&gt;';
              } );    
              localforage.keys(function(err, keys) {
                  r.innerHTML += 'keys: ' + keys + '&lt;br /&gt;&lt;br /&gt;';
              });             
              // Here. Why Uncaught TypeError: Cannot read property 'length' of undefined?
              // How can I solved this problem. Help me.
              alert(arrData.length);
              alert("aad: " + arrData);
              var text = "";
              for(var i=0;i&lt;arrData.length;i++)
                  text += " " + arrData[i];       
              localforage.setItem(key, text, function(e) {
                  var tmp_func = function(err, readValue) { r.innerHTML += 'Read: ' + readValue + '&lt;  br /&gt;'; };
                  r.innerHTML +=   'Saved: ' + text + '&lt;br /&gt;';
              });    
              alert("ccccc");
          };    
              function selectCert(sel){
                  if(parent.middle.document.getElementById("test").innerHTML == "1")
                      parent.middle.document.getElementById("test").innerHTML = "2";
                  else
                      parent.middle.document.getElementById("test").innerHTML = "1";    
                  parent.middle.reload();
              }
          &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;ul&gt;
              &lt;div id="results"&gt;&lt;/div&gt;
              &lt;input id="read-button" type="file" /&gt;
              &lt;li id="qwer" onclick="selectCert(1)"&gt;1&lt;/li&gt;
              &lt;li id="asdf" onclick="selectCert(2)"&gt;2&lt;/li&gt;
          &lt;/ul&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This is my HTML 5 and JavaScript code. It uses local storage, file API, etc. </p>
  
  <p>Why does this code show me the following error?</p>
  
  <blockquote>
    <p>Uncaught Type Error: Cannot read property 'length' of undefined</p>
  </blockquote>