Optimizing for loop in javascript
Posted by Sunil Lukose on Oct 22, 2008
We normally don’t pay much attention when it comes to writing simple loops and assigning variables.
Here I would like to show two ways of writing a simple code that alerts an array’s value.
var arr = new array(”red”,”green”,”blue”);
var len = arr.length;
for(var i=0; i<len; i++) {
var value = arr[i];
alert(value);
}
You could write the same script in a more [...]