I could be wrong about this, but my understanding is that strings are
immutable in JavaScript.  Every time you append to a string what's
actually happening is that a new string object is being created with
its contents set to be the first string plus the second string,
whereas the original string is set aside for garbage collection.

Arrays are not immutable, so you can add elements to them without the
overhead of object creation.

If you have FireFox and FireBug available, try profiling the two loops
below to see the difference:

var str = '';

for (x=0; x<10000; x++)
{
    str = str + 'test ';
}

var arr = [];

for (x=0; x<10000; x++)
{
    arr.push ('test ');
}
str = arr.join ('');


On Jul 17, 12:45 am, jquertil <[EMAIL PROTECTED]> wrote:
> huh. this is an interesting thought. why would the use of join() speed
> things up versus just appending a string variable?
> the reason I'm not concerned about the for() loop is that it seems to
> be quite fast when I output the strHTML in a document.write.
>
> I'm trying to figure out wasy to speed up the rendering by doing
> something other than html()... but I can't think of anything.

Reply via email to