Because the length attribute of arrays is dynamic, and is evaluated
each time you use it.
That's a perfomance optimization.
Also.. if you add items to the array inside the 'for', you'll go into
an infinite loop.

--
Ariel Flesler
http://flesler.blogspot.com

On 11 jul, 08:06, Javier Martínez <[EMAIL PROTECTED]> wrote:
> This is a question about the jquery code. I see many times this type of
> statement *for (var i = 0, j = array.length; i < j; i++)* and want to
> know why is better than* for (var i = 0; j < array.length; i++)
>
> *Because the first statement has more characters and jquery code tends
> to see shorter, I think that there is some reason to do it this way.
> Maybe the second part of the for loop (the comparation) is done on every
> iteration?
>
> Thanks.

Reply via email to