How To Create Downloadable CSV File in JS/Angular

 
import { SecurityContext } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
private sanitizer: DomSanitizer;

downloadCSV() {

     let blob = new Blob([yourdata], { type: 'text/csv' });
     let urlPath  = this.sanitizer.sanitize(SecurityContext.URL, this.sanitizer.bypassSecurityTrustResourceUrl(window.URL.createObjectURL(blob)));
    
      let tempLink = document.createElement('a');
      tempLink.href = urlPath;
      tempLink.setAttribute('download', 'download.csv');
      tempLink.click();
}