JavaScript: for Loops pattern