Since I’ve discovered this snippet, I’m very often using it for iterating over arrays :
for (i = 0; elem = array[i]; i++) doStuff(elem);
It is obviously very wrong if array can contain anything that evaluates to false ('', undefined, null, 0, false). But if you’re sure that this is not the case, does anybody see another risk of using this method ?
I am asking this, since it doesn’t seem to be very commonly used, though it seems really great to me, so I started thinking that there was an obvious drawback I was missing.
You know the drawbacks, as long as you can live with them…
Another way without the drawbacks could be
but it might be more obscure.