title: Get only one element from array of objects in JSON
body: <p>How can I get only the name from JSON file. Also code is perfectly working for getting the data from "file.json" i.e. that's not the problem for sure.</p>
  
  <p>JavaScript:
  <div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var data = [];
  function getName() {
    //what should I write here to get only name from the first object i.e. John
    //with this: data[0].name I am getting error!
  }
  
  var xhttp;
  if(window.XMLHttpRequest)
    xhttp = new XMLHttpRequest();
  else
    xhttp = new ActiveXObject("Microsoft.XMLHTTP");
      
  xhttp.onreadystatechange = function() {
    if(xhttp.readyState == 4) {
      data = JSON.parse(xhttp.responseText);
      getName();
    }
  }
  
  xhttp.open("GET","file.json",true);
  xhttp.send();</code></pre>
  </div>
  </div>
  </p>
  
  <p>"file.json" - JSON:
  <div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>[
    {
      "name":"John",
      "city":"London"
    },
    {
      "name":"Maria",
      "city":"Rome"
    }
  ]</code></pre>
  </div>
  </div>
  </p>