I am successfully parsing, filtering and printing a CSV file using Papa Parse and jQuery. Unfortunately I seem to have managed to set up some sort of loop where the output keeps printing to the webpage.
Code is as below, I know it's probably something obvious but have been working on this for a while now and just can't see for looking!
function organize(data) {
var finalLpc = [];
data.forEach(function(branch) {
if (branch.BranchNo == 1515) {
finalLpc.push(branch);
}
var $tableBody = $('<tbody></tbody>');
for (var i = 0; i < finalLpc.length; i++) {
var branch = finalLpc[i];
var $row = $('<tr></tr>');
$row.append($('<td></td>').text(branch.Area));
$row.append($('<td></td>').text(branch.LPC));
$tableBody.append($row);
}
$('thead').after($tableBody);
});
}
function parseData(url, callBack) {
Papa.parse(url, {
download: true,
header: true,
dynamicTyping: true,
complete: function(results) {
callBack(results.data);
}
});
}
parseData("lpc.csv", organize);
Any help would be greatly appreciated. I have used examples on here to get where I am now.