title: Read CSV file javascript
body: <p>I have file.csv like this:</p>
  <blockquote>
  <p>Name,Gender   //header</p>
  <p>John,M</p>
  <p>Luke,M</p>
  <p>Jessy,F</p>
  </blockquote>
  <p>I want to count total M and F with javascript so I have tried this:</p>
  <pre><code>   &lt;script type=&quot;text/javascript&quot;&gt;
      $(function () {
          $(&quot;#upload&quot;).bind(&quot;click&quot;, function () {
          var regex = /^([a-zA-Z0-9\s_\\.\-:])+(.csv|.txt)$/;
          var F = 0;
          var M = 0;
      
      if (regex.test($(&quot;#fileUpload&quot;).val().toLowerCase())) {
          if (typeof (FileReader) != &quot;undefined&quot;) {
              var reader = new FileReader();
              reader.onload = function (e) {
                  var table = $(&quot;&lt;table /&gt;&quot;);
                  var rows = e.target.result.split(&quot;\n&quot;);
                  for (var i = 0; i &lt; rows.length; i++) {
                      var row = $(&quot;&lt;tr /&gt;&quot;);
                      var cells = rows[i].split(&quot;,&quot;);
                      var gender = cells[1];
                      if (gender === &quot;F&quot;){
                              F++;
                       }else{
                              M++;
                       }
                      for (var j = 0; j &lt; cells.length; j++) {
                          var cell = $(&quot;&lt;td /&gt;&quot;);
                          cell.html(cells[j]);
                          row.append(cell);
                      }
                      table.append(row);
                  }
                  $(&quot;#dvCSV&quot;).html('');
                  $(&quot;#dvCSV&quot;).append(table);
                  window.alert(pos);
              }
              reader.readAsText($(&quot;#fileUpload&quot;)[0].files[0]);
          } 
       });
  });
  &lt;/script&gt;
  </code></pre>
  <p>But <strong>var F &amp; M not increased</strong> (just increased to 1 and didn't increase anymore) , can you help me to solve this problem? :(</p>