title: How to add data into array dynamically and export it client side csv
body: <p>How can i get the input data from users in array and export this data in csv file
  what is the best way to do it using javascript. The form will contain, name, adress, phone, shoes size, city..
  I need to creat a function to my &quot;add&quot; button to keep collection data from user.</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang=&quot;en&quot;&gt;
    &lt;head&gt;
      &lt;meta charset=&quot;UTF-8&quot; /&gt;
      &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot; /&gt;
      &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot; /&gt;
      &lt;title&gt;Document&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;p&gt;Nome&lt;/p&gt;
      &lt;input type=&quot;text&quot; name=&quot;txtname&quot; id=&quot;txtname&quot; /&gt;
      &lt;p&gt;Endereço&lt;/p&gt;
      &lt;input type=&quot;text&quot; name=&quot;txtend&quot; id=&quot;txtend&quot; /&gt;&lt;br /&gt;&lt;br /&gt;
      //How do i do to keep adding data to my spreadsheet using &quot;add&quot; button?
      &lt;button type=&quot;button&quot; id=&quot;txtins&quot;&gt;add&lt;/button&gt;
      &lt;button type=&quot;button&quot; id=&quot;txtcsv&quot;&gt;Download&lt;/button&gt;
      &lt;script&gt;
        document.getElementById(&quot;txtcsv&quot;).addEventListener(&quot;click&quot;, function () {
          var array = [];
          array.push(document.getElementById(&quot;txtname&quot;).value);
          array.push(document.getElementById(&quot;txtend&quot;).value);
          var csv = array.join(&quot;,&quot;);
          console.log(csv);
          var file = &quot;data:text/csv;charset=utf-8,&quot; + csv + &quot;\n&quot;;
          var encoded_file = encodeURI(file);
          var link = document.createElement(&quot;a&quot;);
          link.setAttribute(&quot;href&quot;, encoded_file);
          link.setAttribute(&quot;download&quot;, &quot;file.csv&quot;);
          document.body.appendChild(link);
          link.click();
        });
      &lt;/script&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>