JavaScript String method : lastIndexOf(str)

The lastIndexOf() method returns the index position of the last occurrence of given value or word in a string. It is similar to the indexOf() method, but it returns the last occurrence instead of first occurrence. The syntax would be :
Example :
    var mystr = "This is the Test String for the lastIndexOf() method.";
    var pos = mystr.lastIndexOf("the"); 
    document.write("Position of 'The' is : ", pos);
Output :

If the provided value is not found then it will return -1.

Next Topic :