3 ms·
Hey, I needed JS CSV parser few days ago. Here is my parser, I bet it is 100 times faster than yours :) function parseCSV(str) { var obj = {}; var line
by IvanK_net 12y ago
Hey, I needed JS CSV parser few days ago. Here is my parser, I bet it is 100 times faster than yours :)
function parseCSV(str)
{
var obj = {};
var lines = str.split("\n");
var attrs = lines[0].split(",");
for(var i=0; i<attrs.length; i++) obj[attrs[i]] = [];
for(var i=1; i<lines.length-1; i++)
{
var line = lines[i].split(",");
for(var j=0; j<line.length; j++)
obj[attrs[j]].push(line[j]);
}
return obj;
}
- scrabble 12y agoLooks like you've missed values enclosed in quotes that might contain new line characters or commas -- very important for things like address fields.
- notduncansmith 12y agoCongratulations, this code failed to properly parse my CSV at least 100 times faster than OP's :)