JSFiddle - React, Tailwind, and code Playground

HTML

<table>
  <thead>
    <tr>
      <th>First Name</th>
      <th>Last Name</th>
      <th>Email Id</th>
      <th>Phone Number</th>
      <th>Prefered Contact</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>James</td>
      <td>Miles</td>
      <td>[email protected]</td>
      <td>9876543210</td>
      <td>email</td>
    </tr>
    <tr>
      <td>John</td>
      <td>Paul</td>
      <td>[email protected]</td>
      <td>9638527410</td>
      <td>phone</td>
    </tr>
    <tr>
      <td>Math</td>
      <td>willams</td>
      <td>[email protected]</td>
      <td>99873210456</td>
      <td>phone</td>
    </tr>
  </tbody>
</table>
<a id="save" href="">
  Download file
</a>

JavaScript

userDetails='';
$('table tbody tr').each(function(){
  var detail='(';
  $(this).find('td').each(function(){
  	detail+=$(this).html()+',';
  });
  detail=detail.substring(0,detail.length-1);
  detail+=')';
 userDetails+=detail+"\r\n";
});
var a=document.getElementById('save');
a.onclick=function(){
    var a = document.getElementById("save");
    var file = new Blob([userDetails], {type: 'text/plain'});
    a.href = URL.createObjectURL(file);
    a.download = "data.txt";
}