title: Wrapping a function with an aych loop with a promise
body: <p>I'm new to Javascript and still wrapping my mind around writing promises.</p>
  
  <pre><code>function addToList(data) {
      conversationList = data.Body.Conversations
      console.log(conversationList)
      for (i=0; i&lt;conversationList.length; i++) {
          fullInbox.push(conversationList[i])
      }
      console.log(fullInbox.length)
  }
  
  var fullInbox = []
  var maxLenReturn = 200
  var offset = 0
  function fetchData(offset){
      fetch(asynchCall)
      .then(response=&gt;{return response.json()})
      .then(data=&gt;{
          var fullLength = data.Body.TotalConversationsInView
          console.log(fullLength)
          addToList(data)
          if (offset &lt; fullLength-maxLenReturn) {
              offset+= maxLenReturn
              fetchData(offset)
          }
      })
  }
  
  fetchData(offset) 
  // trying to make something like this work
  .then( .... console.log(fullInbox.length))
  </code></pre>
  
  <p>I have a loop inside the <code>fetchData</code> function and want to wrap it in a promise so that when its done, I can print out the <code>fullInbox</code></p>
  
  <pre><code>var promise1 = new Promise(function(resolve, reject) {
    var fullInbox = []
    var maxLenReturn = 200
    var offset = 0
    fetchData(offset);
    resolve(fullInbox)
  });
  
  promise1.then(function(value) {
    console.log('promise resolved')
    console.log(value);
  });
  </code></pre>
  
  <p>I think I need the <code>resolve</code> inside <code>fetchData</code> but unsure how to write it so that it will loop through everything before resolving. </p>