Im confused

You actually just answered your question. length is returning the length of the object.
If it is a string with 5 letters it will return 5. If it is an array with 9 items it will return 9.
Whenever you call on the index of a string (or array) you are calling each element based on its index; which starts with zero.

That means that a string with length = 5 will have indices of 0, 1, 2, 3, 4 (a total of 5)
And a loop would be zero to length minus 1 (a very common construct in most programming languages.