title: How to download file with javascript?
body: <p>I want to be able to download a given file when pressing a button.The file will be provided via an <code>API</code> call.For now, I will have it in my local storage.
  So my folder is something like :</p>
  
  <pre><code>rootFolder
  -JS file
  -HTML file
  -download file (`sample.csv`)
  </code></pre>
  
  <p>How can I create a download <code>link</code>?
  I have tried so far with :
  <code>&lt;a download="sample.csv"&gt;&lt;/a&gt;</code>
  I have also tried using an <code>onclick</code> event:</p>
  
  <pre><code>&lt;a download="sample.csv" onclick="download()"&gt;&lt;/a&gt;
  
  function download|(){
     .....code that calls the `api`
  }
  </code></pre>
  
  <p>I do not know how these 2 fit: <code>the download</code> API if there is one and the <code>click</code> event handler if you plan to do additional logic when downloading.</p>