title: Trouble concatenating data from within nested functions and if statements
body: <p>Will try to explain this as best as possible with my limited knowledge but sorry if it's not completely coherent!</p>
  <p>Context - Using puppeteer I'm aiming to extract a list of SKU's from a number of business webpages (all structured the same) that each has a number of pages.</p>
  <p>Issue - I am able to loop through the businesses and the pages and retrieve from them the SKUs, I know this as the console log works but when I try to concatenate the SKUs to the object for each business it's not happening. I think it's to do with the nested functions and if statements but I'm not sure. <strong>How can I pass out the list of SKUs from each page and concatenate it to the object for each business?</strong></p>
  <p>Below is my code:</p>
  <pre><code>const puppeteer = require('puppeteer');
  
  //businesses
  const businessURLs = {
    businessA: {
      url: '...',
      SKUS: []
    },
    businessB: {
      url: '...',
      SKUS: []
    },
    businessC: {
      url: '...',
      SKUS: []
    },
  };
  
  //Function to retrieve products
  async function retrieveProducts(businessURLs) {
    try {
  
        //Load broswer
        const browser = await puppeteer.launch({ headless : false });
        const page = await browser.newPage();
        page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.90 Safari/537.36');
  
      //loop through business websites
      for ( const business in businessURLs) {
  
        //Go to  page
        await page.goto(businessURLs[business].url, {waitUntil: 'networkidle2'});
        await page.click(&quot;#a-autoid-0 &gt; span&quot;,{delay: 10});
        await page.waitForSelector('.s-no-outline');
        console.log(&quot;business loaded&quot;);
  
          //define number of pages.. will be dynamic, just not for now. 
          var lastPageNumber = 15;
  
          //pagination loop
          for (let index = 0; index &lt; lastPageNumber; index++) {
  
            // wait 1 sec for page load
            await page.waitForTimeout(1000);
  
            // Collecting SKUs on a page
            let SKU = await page.evaluate(() =&gt; Array.from(document.querySelectorAll('.s-result-item.s-sku.sg-col-0-of-12.sg-col-16-of-20.sg-col.s-widget-spacing-small.sg-col-12-of-16'), e =&gt; e.getAttribute('data-sku')));
            //test to make sure SKUs retrieved
            console.log(SKU);
            //add SKUs to businessURLs object
            businessURLs[business].SKUS.concat(SKU)
  
            //determine if next page button exists
            if (await page.$('.s-pagination-item.s-pagination-next.s-pagination-button.s-pagination-separator') !== null) {
              //determine if on last page
              if (index != lastPageNumber - 1) {
                //if next button exists and not on last page, click next button
                await page.click('.s-pagination-item.s-pagination-next.s-pagination-button.s-pagination-separator');
              }
            }
          };
        
        console.log(businessURLs[business].SKUS);
      };
  
  } catch (err) {
      console.log('Error - ', err.message);
    } 
    
  };
  
  //browser.close();
  
  //Run the code
  retrieveProducts(businessURLs);
  </code></pre>