title: Reading JSON file and convert into array
body: <p>I have a <strong>JSON file</strong> <code>data.json</code> with the following content:</p>
  
  <pre><code>[
     {
      "name": "Alice",
      "number": 10 
     },
     {
      "name": "Bob",
      "number": 20 
     },
     {
      "name": "Mary",
      "number": 50 
     }
  ]
  </code></pre>
  
  <p>And I want to read this JSON file and extract the value of <code>key: number</code> into an array:
  <code>number_array = [10, 20, 50]</code></p>
  
  <hr>
  
  <p>Here is my way:</p>
  
  <p>First I <strong>read</strong> the JSON file into a <strong>string</strong></p>
  
  <pre><code>function readTextFile(file) {
     var raw_text;
     var rawFile = new XMLHttpRequest();
     rawFile.overrideMimeType("application/json");
     rawFile.open("GET", file, true);
     rawFile.onreadystatechange = function() {
          if (rawFile.readyState === 4 &amp;&amp; rawFile.status == "200") {
               raw_text = rawFile.responseText;
          }
      }
      rawFile.send(null);
      return raw_text;
  }
  </code></pre>
  
  <p>However, when I call this function, </p>
  
  <pre><code>var result = readTextFile('data.json')
  </code></pre>
  
  <p>I <strong>cannot</strong> get the correct result but an <code>undefined</code>.</p>
  
  <hr>
  
  <p>I am asking how can I read the JSON file and store it into a global variable (not only within the function local variable). Thank you.</p>