Win a copy of Design for the Mind this week in the Design forum!

# .lastIndexOf

Tim Holmes
Greenhorn
Posts: 25
I am trying to undestand what is going on here:

I know that it is starting at index 10 and figured out that is zero based so it is starting at the "n" of the second "One". Then it counts backwards to find the the last occurrence of "One". The example I am looking at says it is "9", but if i count backwards like when finding the starting index, the "n" of the second "One" is zero and 9 is the "n" of the first "One". Right?

Henry Wong
author
Marshal
Posts: 20997
76
but if i count backwards like when finding the starting index, the "n" of the second "One" is zero and 9 is the "n" of the first "One". Right?

No. The index of the characters doesn't change -- the index is the index relative from the beginning starting from zero. I don't know about you but it would really be confusion if the index is based on how the method is called.

Henry

Tim Holmes
Greenhorn
Posts: 25
Ah that makes sense...thanks!