# .lastIndexOf

Tim Holmes

Greenhorn

Posts: 25

posted 7 years ago

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?

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?

posted 7 years ago

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

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