title: Saving the output of an HTML form in an js object
body: <p>I want to save the output of this form</p>
  <p>I can see the results in the console for a split second before it disappears. I'm trying to create something similar to <code>state</code> in react.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>let sbmt = document.getElementById('myForm');
  
  sbmt.addEventListener("submit",
    function setData() {
      let nodeList = document.forms[0].elements;
      let flatNodeList = [...nodeList].map(x =&gt; x.value).filter(x =&gt; x != "Submit");
      let objData = {
        userName: flatNodeList[0],
        userGender: flatNodeList[1],
        userAge: flatNodeList[2]
      };
      console.log(objData);
      return objData;
    }
  );</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="container"&gt;
    &lt;h1&gt;Form&lt;/h1&gt;
    &lt;form name="inputForm" id="myForm"&gt;
      &lt;label for="iname"&gt;Name&lt;/label&gt;
      &lt;input class="inputs" id="iname" name="iname" type="text " placeholder="Name" value=""&gt;
      &lt;label for="igender "&gt;Gender&lt;/label&gt;
      &lt;input class="inputs" id="igender" name="igender" type="text" placeholder="Gender" value=""&gt;
      &lt;label for="iage"&gt;Age&lt;/label&gt;
      &lt;input class="inputs" id="iage" name="iage" type="number" placeholder="Age" value=""&gt;
      &lt;button class="submitbutton" id="formbutton" type="submit" value="Submit"&gt;Submit&lt;/button&gt;
    &lt;/form&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>