"At first I just thought it was an issue with variable types in the comparison but typeof returns number for both i and length." . . . .