I manage to get this work but how to actually make it this happen when the variable actually is an array of multiple objects which you can write to each lines with blob?
var line1 = "firstline";
var line2 = "secondline";
var blob = new Blob([line1 + "\r\n", line2], {type: "application/txt"});
var url = URL.createObjectURL(blob);
var a = document.createElement('a');
a.download = "test.txt";
a.href = url;
a.textContent = "Download test.txt";
document.getElementById('test').appendChild(a);