I read that it is advised to optimize loops in JavaScript by [*not* reading the length attribute of an array every iteration in the loop header](http://dev.opera.com/articles/view/javascript-best-practices/#loops).

So, we should rather do this:

```
var names = ['George','Ringo','Paul','John'];
for(var i=0,j=names.length;i<j;i++){// Read array length once and assign it to a variable
    doSomeThingWith(names[i]);
}

```

instead of this:

```
var names = ['George','Ringo','Paul','John'];
for(var i=0;i<names.length;i++){
    doSomeThingWith(names[i]);
}

```

However, I [created a small testcase](http://jsperf.com/for-vs-length) to compare the two techniques, but sometimes the first case was faster and sometimes the second one.

**Which version would you recommend?**