I am trying to get my 2D array to export as a .csv file. My array is in the form: [[1,2],[],[3],[4,5,6]]. I would like the spreadsheet to be formatted as
h1 h2 h3 h4
1 3 4
2 5
6
I cannot change the format I receive the data in. I've looked into ways to transpose the array but the solutions I've seen don't work with variable size arrays like mine. So far my only idea (in psuedoish code) is:
for (i < length of longest column; i++) {
var arr = [];
if (i > col1.length) arr.push("");
else arr.push(col1[i]);
//so on for rest of cols
csvFile += arr;
}
Is there a better way to do it?