title: How can I pass json data returned from a Fetch function to another function?
body: <p>I want a use <code>Fetch()</code> or Jquery GetJson() to fetch some json data (json file) every 5 seconds independently.</p>
  
  <p>I want another function to use that data and display an array of names choosing 8 at a time (out of 100 or so names) in a loop. (still to be implemented)</p>
  
  <p>How do I go about waiting for the data? I know I need to wait for the data to return asynchronously.</p>
  
  <pre><code>var data = null;
  var dataPath = "../data/GolfData.json";
  
  $(document).ready(function () {
    console.log('working...');
    DisplayData(data);
  });
  
  
  /* Fetch Data
  ------------------------------------------  */
  function FetchData() {
    fetch(dataPath)
      .then(function (response) {
        return response.json();
      })
      .then(function (json) {
        data = json;
        console.log(data)
        return data;
      })
      .catch(function (error) {
        setInterval(FetchData, 5000);
        console.log(error);
      })
  }
  FetchData();
  setInterval(FetchData, 5000);
  
  function DisplayData(data) {
   console.log('data ', data);
  }
  </code></pre>
  
  <p>Console: data  null</p>