title: Return variable from a reader.onload event
body: <p>I am reading an array via <code>JavaScript</code> and saving the size of that array in a reader.onload event. I think that the <code>reader.onload</code> function is called when the file has finished uploading. 
      <code>event.target.result</code> stores that array. I would like that array saved as a variable to be used in other functions but, I tried initializing an empty array and using the    </p>
  
  <pre><code>slice 
  </code></pre>
  
  <p>function but, it didn't work. The console returns an undefined value. </p>
  
  <p>Here is the code </p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt; Home Page &lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;input type="file" id="file" name="files[]" multiple/&gt;
      &lt;output id="list"&gt;&lt;/output&gt;
  
      &lt;p id="demo"&gt;&lt;/p&gt;
  
      &lt;script&gt;
        function handleFileSelect(evt) { 
          // grab the file that was uploaded which is type File. 
          // evt is the event that was triggered
          // evt.target returns the element that triggered the event 
          // evt.target.files[0] returns the file that was uploaded, type File
          var file = evt.target.files[0]; 
  
          var myArray = [];
          // instantiate a FileReader object to read/save the file that was uploaded
          var reader = new FileReader();
            // when the load event is fired (the file has finished uploading) this function is called
          reader.onload = function(event) {
            // the result attribute contains an ArrayBuffer representing the file's data. 
            var arrayBuffer = event.target.result;
            myArray = arrayBuffer.slice(0);
            document.getElementById("demo").innerHTML = arrayBuffer.byteLength;
          }
  
          // read the file and save as an array. Once the read is finished loadend is triggered
          reader.readAsArrayBuffer(file);
          console.log(myArray.byteLength);
        }
  
        //console.log(myArray.byteLength);
        document.getElementById('file').addEventListener('change', handleFileSelect, false);
      &lt;/script&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p> </p>