In this code I am trying to render the csv data into tabular form after doing some processing on it. The result I am getting is in form:

whereas, I need to get the result like this:
I tried with ._zip_underscore and it is giving me an exception with underscore.js file. I am not sure how to do that. Please help. Code is below.
JavaScript
function execData(file)
{
var reader = new FileReader();
reader.readAsText(file);
reader.onload = function (event)
{
var csv = event.target.result;
var data = $.csv.toArrays(csv);
var data1 = data;
var header = data1.shift();
var numeric = 0;
var str = 0;
var dtr = new Array();
for (var i = 0; i < data1[i].length; i ++ )
{
// alert("backa");
for (var m = 0; m < data1[m].length; m ++ )
{
for (var j = 0; j < data1.length; j ++ )
{
var r = data1[j][i];
dt(r);
}
dttop(m);
}
}
function dt(x)
{
// alert("here");
if (isFinite(x) == true)
{
numeric ++ ;
}
else
{
str ++ ;
}
}
function dttop(f)
{
if (numeric > str)
dtr[f] = "n";
else
dtr[f] = "s";
}
// alert(dtr);
var final = dtr.concat(data1);
// to render in a tabular format
var html = '';
for (var row in final)
{
html += '<tr>\n';
for (var item in final[row])
{
html += '<td>' + final[row][item] + '</td>\n';
}
// alert(html);
html += '</tr>\n';
}
$('#contents').html(html);
};
reader.onerror = function ()
{
alert('Unable to read ' + file.fileName);
};
}
HTML
<div id=inputs class=clearfix>
<input type=file id=files name=files[] multiple />
</div>
<hr />
<output id=list></output>
<hr />
<table id=contents style="width:100%; height:400px;"></table>