title: Get data from a Promise
body: <p>I'm working with <a href="https://github.com/jsoma/tabletop" rel="nofollow noreferrer">Tabletop.js</a> to get data from my Google Spreadsheet. In the function, I've invoked a Promise. The only problem is I can't get the data(which is an Array) out of the function.</p>
  
  <p>I have the following code:</p>
  
  <pre><code>function getData() {
  
    return new Promise((resolve) =&gt; {
      Tabletop.init({key: publicSpreadsheetUrl, callback: showInfo, simpleSheet: true})
      resolve('Done');
    })
  }
  
  let arrayWithData = [];
  
  function showInfo (data, tabletop) {
    console.log('showInfo active');
    arrayWithData.push(...data);
    return new Promise(resolve =&gt; {
      console.log(arrayWithData, 'data is here')
      resolve(arrayWithData) // This doesn't work yet
    })
  }
   showInfo().then(data =&gt; {
     console.log(data, 'data from the Promise')
   }) // This doesn't work
  </code></pre>
  
  <p>I want to use the Array later on in React blocks</p>
  
  <p><strong>Edit</strong>
  With the snippet of Keith, I've got my code working &amp; also added a <code>reject</code> handler(inside my Promise of getData() ) from the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject#Examples" rel="nofollow noreferrer">MDN site</a>. </p>
  
  <pre><code>Promise.reject(new Error('fail')).then(function() {
    // not called
  }, function(error) {
     console.log(error); // Stacktrace
  });
  </code></pre>
  
  <p>The only thing is, that I don't understand the error I get from my <code>Promise.reject</code>. It returns the following error:</p>
  
  <pre><code>Error: fail
  at eval (eval at hmrApply (base.eaab6c8c.js:297), &lt;anonymous&gt;:37:20)
  at new Promise (&lt;anonymous&gt;)
  at getData (eval at hmrApply (base.eaab6c8c.js:297), &lt;anonymous&gt;:30:10)
  at Object.eval (eval at hmrApply (base.eaab6c8c.js:297), &lt;anonymous&gt;:63:1)
  at newRequire (script.726c79f3.js:48)
  at hmrAccept (base.eaab6c8c.js:328)
  at base.eaab6c8c.js:214
  at Array.forEach (&lt;anonymous&gt;)
  at WebSocket.ws.onmessage (base.eaab6c8c.js:212)
  </code></pre>