0

I am still a beginner in JavaScript. I have written a code with two nested for-loops. It achieves the result but that is too large to be copied in Android. It copies part but not all data.

How can I export my data as .csv file or .txt file i.e. a button in HTML file, I click on it then the data is exported as .csv?

My HTML code:

<html>
<head>
<title>Page Title</title>
</head>
<body>
<button onclick="convert()"> Convert </button>
</body>
</html> 

My JavaScript code:

function convert(){
var lon,lat;
     for(lat = 52 + (2226/3600) ; lat <= 52 + (2425/3600) ; lat=lat+(1/3600)) 
     { 
    for(lon = 9 + (3539/3600) ; lon<= 10 + (215/3600) ; lon=lon+(1/3600)) 
{ document.write("W,"+lat+","+lon+"<br>") } 
}
 }; 

My data are browsed fully and without problem in webpage HTML as followed after clicking convert button:

W,52.61833333333333,9.983055555555556 W,52.61833333333333,9.983333333333333 W,52.61833333333333,9.98361111111111 W,52.61833333333333,9.983888888888886 W,52.61833333333333,9.984166666666663 .......... W,52.61833333333333,9.98444444444444

Hopefully I can export all these data so as .csv or .txt file.

Khaled
  • 27
  • 2
  • 9
  • You can use `Blob` and `Blob URL` – guest271314 Oct 23 '17 at 04:27
  • Try this: https://stackoverflow.com/questions/14964035/how-to-export-javascript-array-info-to-csv-on-client-side – Dabbas Oct 23 '17 at 05:36
  • @Dabbas I have seen already your link and I searched in Google, but all these topics speak about array to csv... but my problem is a list of data resulting of two nested for loops, I would export it as csv not as document.write – Khaled Oct 23 '17 at 14:55

0 Answers0