Length evaluation moved outside the loop

Standard JS best practice