title: Why is my Firestore documents' array field always only updated with one less item than the array I send from the front end?
body: <p>I am trying to update a Firestore document once I save files to Google Cloud Storage. I want to send an array of URLs of the stored files to a document in Firestore as follows...</p>
  
  <pre><code>(attachments: [ {url: "fileone.jpeg", ...}, {url: "filetwo.jpeg", ...}, ...]).
  </code></pre>
  
  <p>This array of URLs are created at the front end by using firebases <code>getDownloadURL()</code>. I can successfully update my document but the array in the updated document always holds one less item than the array created at the front end. When <code>console.log</code>-ing the array stored in memory (to be sent to firestore) I see that the value within parentheses that preceeds the <code>[{},{}]</code> is one less than array.length as well.</p>
  
  <p>What console logging the fileUrls array (stored in memory to be sent to firestore) shows even though <code>fileUrls.length === 3</code> and expanding this below line shows all three URL containing objects starting at index 0 :</p>
  
  <pre><code>fileUrls: &gt; (2) [{…}, {…}]
  </code></pre>
  
  <p>Here is the code from implementing this update process:</p>
  
  <pre><code>let fileUrls = [];               // &lt;&lt;-- Array for file urls to be stored
  let promises = [];
  
  for (const file of state.post.files) {
    const fileRef = storage.ref().child(`my file path`);
    const p = fileRef.put(file)
      .then(snapshot =&gt; {
        fileRef.getDownloadURL()
          .then(url =&gt; {
            fileUrls.push({ url: url, type: file.type })  // Adding urls to arr
          })
      })
  
    promises.push(p);
  }
  
  const all = Promise.all(promises);
  all
    .then(() =&gt; {
      submissionRef.update({         // &lt;&lt;&lt;--- Updating document created prior.
        attachments: fileUrls
      })
    })
    .catch(err =&gt; console.log(err));
  </code></pre>