title: How to access output from .then statement from fetch request and use it outside of function
body: <p>I have the function below that sends a fetch request and return a JSON result, I have checked the response and it does return a value that I need, return userid does return me a value, the problem is when I call this function it returns an undefined value even though I have checked it does return a value with the function.</p>
  <p>I am looking for a simple solution.</p>
  <pre><code>function currentloginid() {
      fetch('http://localhost/gaq/api/api.php?action=userid', {
         method: 'GET',
      }
  )
      .then(function(response) {
          response.json().then(function(data) {
              var userid = JSON.parse(data);
              console.log(userid);
              return userid;
          })
      })
  }
  </code></pre>