On Fri, Feb 18, 2011 at 4:04 PM, Nick Morgan <[email protected]> wrote:
> Hi all
> This is something I've come across a lot, and I was wondering people's views
> on it.
> When I'm looping through an array I generally do either this:
> var arr = [1, 2, 3, 4];
> for (var i = 0; i < arr.length; i++) {
> console.log(arr[i]);
> }
> or this:
> for (var i = 0, len = arr.length; i < len; i++) {
> console.log(arr[i]);
> }
>
Both are readable. As for the typing you can use snippets. If the
order doesn't matter you can even write:
| for (var i = arr.length; i--;) {
| console.log(arr[i]);
| }
This is my personal favourite iteration. Small, fast, readable.
- Balázs
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]