title: Making a fetch call within a nested for loop
body: <p>I'm currently converting my local function into a lambda function and am running into a few hardships. In a previous method, I get an array of url fragments that I have to string along programmatically to a prefix to get the data back.</p>
  
  <p>Logically, I figure the best way of doing this is to do a nested for loop. Go through the series of prefixes adding the url fragment and doing the fetch call.</p>
  
  <p>It works fine in local, but lambda throws errors.</p>
  
  <pre><code>function getVariantData(data, cb) {
    for (var i = 0; i &lt; chapters.length; i++) {
      let source = chapters[i];
  // chapters = url prefix
      data.forEach(async element =&gt; {
        let res = await fetch(chapters[i] + element);
  //element = url fragment
        let body = await res.text();
        createVariantsFile(element, source, body, cb);
      });
    }
  }
  </code></pre>
  
  <p>this code runs fine but i've learned that lambdas are a bit more strict with forEach and async/awaits so I've changed my code to this and I've been dealing with a mess of issues. I havent gone past writing console.log because...well I haven't gotten past the error.</p>
  
  <pre><code>async function getVariantData(data, cb) {
    for (var i = 0; i &lt; chapters.length; i++) {
      let source = chapters[i];
      const promises = data.map((datum, index) =&gt; fetch(source+datum))
      const chapterData = await Promise.all(promises)
      console.log(chapterData)
      // await data.map(async element =&gt; {
      //   return await (chapters[i] + element);
      //  createVariantsFile(element, source, body, cb);
      // });
    }
  }
  </code></pre>