title: Use await inside for loop inside async function
body: <p>I am using puppeteer and node.js to scrape some data, but I am having some problems when trying to loop a list of url:s. When I push the scraped data, I got an error saying that the array is not defined. I think the problem has to do with using await inside the for loop, but I don't really understand why and how to fix it. Why does it says that the array is not defined?</p>
  <p>Here is a very simplified version of my code:</p>
  <pre><code>const scrapeJobInfo = async (links) =&gt; {
    
    /* Initiate the Puppeteer browser */
    const browser = await puppeteer.launch(); 
    const page = await browser.newPage();
  
    /* Empty array for pushing the data */
    const jobData = [];
  
    /* For loop that push the data */
    for(let i = 0; i &lt; links.links.length; i++ ) {
      let linkUrl = `${links.links[i]}`
      await page.goto(linkUrl, { waitUntil: 'networkidle0' });
      let companyInfo = await page.evaluate(() =&gt; {
        jobData.push('hi') //&lt;-- ReferenceError: jobData is not defined 
      });
    } 
  
    /* Close browser and log jobData */
    await browser.close();
    console.log(jobData)
  };
  </code></pre>