title: How to read in the contents of a CSV file as a string?
body: <p>I want to import a CSV file, store its contents as a string, and parse the string into a series of JSON objects. However, I am stuck on how to store CSV contents as a string.</p>
  <p>I have the following code for picking a File object from the local file system:</p>
  <pre><code>var fileList = document.getElementById('loadLocalFilePath').files;
  var fileObj = fileList[0];//contains the csv file. 
  console.log(fileObj);
  </code></pre>
  <p>Which I know works, because it properly logs:</p>
  <pre><code>File {name: &quot;ChronoVizProject.csv&quot;, lastModified: 1606608282054, lastModifiedDate: Sat Nov 28 2020 19:04:42 GMT-0500 (Eastern Standard Time), webkitRelativePath: &quot;&quot;, size: 708, …}
  </code></pre>
  <p>However, I don't want the details of the File object, but rather the CSV contents as a string.
  I read this: <a href="https://developer.mozilla.org/en-US/docs/Web/API/FileReader/result" rel="nofollow noreferrer">https://developer.mozilla.org/en-US/docs/Web/API/FileReader/result</a> and added the following code:</p>
  <pre><code>var reader = new FileReader();
  var fileContents = reader.readAsText(fileObj);
  console.log(fileContents);
  </code></pre>
  <p>However, <code>fileContents</code> logs as <code>undefined</code>, as does <code>fileObj.results</code>.</p>