title: Get an array of values using fetch api javascript
body: <p>I am using fetch api to read a txt file via javascript. I want to load the contents of the txt file which are separated by new line in an array.</p>
  
  <p>Text file:</p>
  
  <pre><code>A
  B
  C
  </code></pre>
  
  <p>I need it in the following format:</p>
  
  <pre><code>arr = ["A", "B", "C"]
  </code></pre>
  
  <p>Below is the code I tried</p>
  
  <pre><code>var arr = []
  fetch('file.txt')
    .then(function(response) {
      return response.text();
    }).then(function(text) {
  arr.push(text)
  console.log(text)
  
      });
    console.log(arr)
  </code></pre>
  
  <p>Nothing gets added to my array, however the data from the text file gets printed on the console.</p>