[jQuery] Best practice for processing JSON quickly
I have some JSON that needs processing, e.g.:
items["1"] =
'101010111110010101020110111110100010101020101020101010101100110100";
items["2"] =
'000010101210101011100101101010000111111001010121010000111110001111";
... (x 1000)
I need to process ~1000 rows so that each 0, 1 or 2 appear as a small
coloured dot. (It's a visualization thing).
So here's what I have so far, which works:
for (i in items) {
html += process (items[i]);
}
function process (item) {
var result = '<div>';
for (var g=0; g<item.length; g++) {
switch (item.substr(g,1)) {
case "0":
result += '<div class="grey"> </div>';
result;
case "1":
result += '<div class="blue"> </div>';
break;
case "2":
result += '<div class="red"> </div>';
break;
}
}
result += '</div>';
return result;
}
My question is, is there a faster or more efficient way to iterate
through each items' "10101001010220211"? I realize this is not
strictly jQuery related, but it seems the smartest Javascript people
hang out here. :-)
Thanks
...Rene