Is it common practice in Javascript to use the following loop:
for (var i = array.Length - 1; i >= 0; i--) { /* do something here */ };
I haven't seen this in other languages. Are there any advantages to this compared to:
for (var i = 0; i < array.Length; i++) { /* do something here */ };
The only benefit I can think of is caching the array length in the first option, which may not significantly improve performance. Another approach could be:
var top = array.Length;
for (var i = 0; i < top; i++) { /* do something here */ };
This provides the same caching benefit, but may be slightly less performant if you are trying to minimize your code (saving around 8 characters when minifying the script).