I'm not sure if it matters in javascript but I would do this:

var length = item.length;
for ( var g = 0; g < length; g++) {

Instead of this:

        for (var g=0; g<item.length; g++) {


Cam

On Wed, Mar 4, 2009 at 2:28 PM, James <james.gp....@gmail.com> wrote:

>
> Not sure how much it'll speed up, but instead of:
> item.substr(g,1)
> try: item[g]
>
> Then, go through this post:
> http://www.learningjquery.com/2009/03/43439-reasons-to-use-append-correctly
> (
> http://groups.google.com/group/jquery-en/browse_thread/thread/9889ebd5e10c9122
> )
>
> Instead of concatenating strings into one results variable, use array
> items, and then join them at the end.
>
> On Mar 3, 3:11 pm, René <renefourn...@gmail.com> wrote:
> > 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">&nbsp;</div>';
> >                                 result;
> >                         case "1":
> >                                 result += '<div
> class="blue">&nbsp;</div>';
> >                                 break;
> >                         case "2":
> >                                 result += '<div
> class="red">&nbsp;</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
>

Reply via email to