title: Refilling a form from a database
body: <p>I'm so stuck on this I might not even be able to formulate a sensible question, but here goes...</p>
  
  <p>I have a gigantic (and occasionally changing) form.  I've found a reasonable way to get all the data from the form, turn it into an object, and save it to Firebase all at once.  It looks like this, and is working fine (I think): </p>
  
  <pre><code>const incidentReport = document.getElementById('incident-report-form');
  let irv = {};
  // This works. All form data is saved to an object (as required by firebase), with the question as the name and the answer as the value.
  incidentReport.addEventListener('submit', (e) =&gt; {
    e.preventDefault();
    [...incidentReport.elements].forEach((item) =&gt; {
      let name = item.name;
      let value = item.value;
  
      irv = { ...irv, [name]: value };
    });
    // After all data is collected in one object, I send it to the database all at once.
    db.collection('incident reports').add(irv);
  });
  </code></pre>
  
  <p>Okay, so far so good... Now I want to get it back out of the database (I know how to do this) and repopulate the same form (no idea).  I'm 100% stumped and I don't even know what to try.</p>
  
  <p>Please forgive me if this is super easy and my brain is just shutting off... it's been a rough day.
  Thanks in advance.</p>
  
  <p>EDIT - This seems to work? I'm still very open to criticism and/or improvements.</p>
  
  <pre><code>    // Get data from incident reports 
  //@TODO -&gt; Need to create a list of incident reports, and then load the one //the user clicks on. 
  //Right now there is only one incident report in the database for testing.
      db.collection('incident reports')
        .get()
        .then((snap) =&gt; {
          snap.docs.forEach((element) =&gt; {
            data = element.data(); //Previously declared but not included in this snippet, sorry.
          });
          for (let [key, value] of Object.entries(data)) {
            let x = document.getElementsByName(key)[0];
            if (x !== undefined) {
              x.value = value;
            }
          }
        });
  </code></pre>