Downloading a file using JavaScript

This is a way to download a file by utilizing the DOM.

In this scenario, csv is a string variable with all the values to be in the table separated by commas. We specify the URI as csv and aptly name the file “myfile.csv”.

encodeURI is used on the variable csv to enforce escape sequence representation of UTF-8 encoding to the characters of the variable csv.

var uri = 'data:text/csv;charset=utf-8,' + encodeURI(csv);
var link = document.createElement("a");
$(link).hide();
link.href = uri;
link.download = "myfile.csv";
$("body").append(link);
link.click();
$("body").remove(link);
 
10
Kudos
 
10
Kudos

Now read this

Spirally Traversing a Two-Dimensional Array in JavaScript

This is a way to traverse a two-dimensional array (or a matrix) from the top left, spirally in a clockwise manner in JavaScript. This solution is inspired by functional programming and it uses tail recursion. Steps: When you start with... Continue →