title: Cypress: Async function using for loop giving same results
body: <p>I'm new to cypress framework and trying to achieve the below functionality using cypress.</p>
  <p>I have a page with table rows and a dropdown menu on page header. On selecting the option, the dropdown menu gets closed and the body content gets changed/loaded up according to the selected menu options.</p>
  <p>Problem: Getting the same length for the table rows for all the menu options selected sequentially, although the table rows count is different for the options.</p>
  <p>Here is my code:</p>
  <pre class="lang-js prettyprint-override"><code>it.only('Validate table Row changed length on menu option selection', {defaultCommandTimeout: 10000}, () =&gt; {
    // opening the dropdown menu
    page.openDropdownMenu();
    // getting the dropdown options and calculating the length
    cy.get('dropdownOptions').then($options =&gt; {
      // calculating the length
      const menuOptionCount = $options.length;
      // closing the dropdown menu
      page.closeDropdownMenu();
      for (let i = 0; i &lt; menuOptionCount; i++) {
        // opening the dropdown menu
        page.openDropdownMenu();
        // clicking the menu option
        $options[i].click();
        // closing the dropdown menu
        page.closeDropdownMenu();
        cy.get(&quot;body&quot;).then($body =&gt; {
          // always getting the same length for the table rows for all selected options
          const rowsLength = $body.find('.table.rows').length;
          cy.log('****************Rows length************', rowsLength);
        });
      }
    });
  });
  </code></pre>
  <p>Is there any way to write the asynchronous statement to synchronous like (await async in promises) without using any external utility in cypress. As in my previous assignment using <a href="https://www.protractortest.org/" rel="nofollow noreferrer">Protractor</a> the same thing could be handled using async await as below.</p>
  <pre class="lang-js prettyprint-override"><code>const elementCount = await element(
    by.css('[title=&quot;Locked By&quot;] .med-filter-header-button div')
  ).count();
  </code></pre>