title: Javascript read text file and append values to array
body: <p>I have a problem with populating a JavaScript array with a function...</p>
  
  <p>I have some charting software that uses JavaScript.  I can input my own values into an array directly to create my desired chart like so: </p>
  
  <pre><code>var data_array=[[0,170],[0,185],[0,179]]
  </code></pre>
  
  <p>The first value in the array corresponds to sample number (e,g, 0) and the second value corresponds to height (e.g. 170, 185 etc).
  This works but I will eventually have a huge list of thousands of values.  The height values will be stored in text files.  There will be a different file for each sample.   The text file will contain a simply list of values separated by lines.</p>
  
  <p>What I need my program to do is open a text file and extract the values and then append them to the data array.  So far I have this:</p>
  
  <pre><code>$.get('sample0.txt', function(data, data_array){
  
      var lines=data.split('\n');
      for (var i=0; i&lt;lines.length-1;i++){
          var item=lines[i];
          data_array.push([0,item]);
      }
      return data_array
  }
  </code></pre>
  
  <p>This doesn't work, although I know it is correctly extracting the values from the text file. I'm not worried about sample number as I can set this for each file. My problem is how to populate the array and make that array exist outside of the function.</p>
  
  <p>I normally code in PHP and I apologize that my knowledge of JavaScript is very basic!</p>