I know that in JavaScript, creating a for loop like this: for(int i = 0; i < arr.length; i++)
is costly as it computes the array length each time.
Is this be
All .Net arrays have a field containing the length of the array, so the length is not computed at usage but at creation time.
The .Net virtual machine is very good at eliminating bounds checks whenever possible, this is one of those cases, where the bounds check is moved outside the loop (in most situations, and if not it's just 2 instructions overhead).
Edit:
Array Bounds Check Elimination