Search code examples
javascriptsubstringlastindexof

why does lastindexOf() not find the last element


I'm trying to extract a sub string from a string with Javascript and have come up with the following: http://jsfiddle.net/bbhbz7r6/1/ for some reason however, .lastindexOf() doesn't find the last occurrence of <td class="views-field views-field-line-item-title"> but the first one... and I'm not sure what I'm doing wrong.


Solution

  • It is actually correct. The problem is in the second line which should be

    var tail = string.substring(start, string.length);