Best practice "for i" loop in Javascript