title: JavaScript merge arrays from two different functions
body: <p><strong>Hey I want to merge those two arrays and use it as one array.</strong></p>
  <p>Assigning variables:</p>
  <pre><code>var worldData = [];
  var europeData = [];
  var allData = [];
  </code></pre>
  <p>Code to fetch data from Data Source 1:</p>
  <pre><code>fetch('https://disease.sh/v3/covid-19/all')
      .then((res) =&gt; res.json())
      .then((data_world) =&gt; getWorldData(data_world));
  </code></pre>
  <p>First function:</p>
  <pre><code>const getAllData = (data_world) =&gt; {
    worldData = [
      data_world.todayCases,
      data_world.todayRecovered,
      data_world.todayDeath
    ];
    
    return worldData;
  };
  </code></pre>
  <p>Code to fetch data from Data Source 2:</p>
  <pre><code>fetch('https://disease.sh/v3/covid-19/continents/Europe?strict=true')
      .then((res) =&gt; res.json())
      .then((data_eu) =&gt; getEuropeData(data_eu));
  </code></pre>
  <p>Second function:</p>
  <pre><code>const getEuropeData = (data_eu) =&gt; {
    europeData = [
      data_eu.todayCases,
      data_eu.todayRecovered,
      data_eu.todayDeath
    ];
    
    return europeData;
  };
  </code></pre>
  <p>Merging arrays (didn't work):</p>
  <pre><code>allData = [...worldData, ...europeData]
  allData = worldData.concat(europeData)
  </code></pre>
  <p><strong>I can't put arrays outside these functions because i'm fetching data from two different sources and I want to store all data inside one array.</strong></p>