Quickest way to convert from CSV to object array
I have a large string that comes across the wire using an $.ajax request.
I can format the string any way necessary, and currently am using a % as
the line delimiter and , as the item delimiter. Considering performance is
so essential in my application, does anyone have a quicker way to do the
following? Thank You
function convertCSV(s) {
var lines = s.split("%");
var items, sym, arr = [];
for (var x = 0, len = lines.length; x < len; x++) {
items = lines[x].split(",");
sym = {};
sym.time = +items[0];
sym.num1 = +items[1];
sym.num2 = +items[2];
sym.a1 = +items[3];
sym.b1 = +items[4];
sym.c1 = +items[5];
sym.d1 = +items[6];
sym.e1 = +items[7];
sym.f1 = +items[8];
sym.g1 = +items[9];
sym.h1 = +items[10];
sym.l1 = +items[11];
arr[x] = sym;
}
return arr;
}
No comments:
Post a Comment