Table of Contents
lastIndexOf() method returns the last position within a String object which an element can be found. The search starts from the last position of the String object. The method will return
-1 if the specified parameter cannot be found.
"hello world scotch world".lastIndexOf("world") // 19
const indexOfLastOccurence = string.lastIndexOf(searchParam, startIndex)
This is the string value to search for within the String object -
This is the index at which the search will begin. Search typically begins from the string
.length - 1 index, which is the last position of the object. If the length of the provided string is
0, or if no item was found, it returns
Returns a number
The method returns a number whch is the index of the last occurence of the search parameter.
This method is case sensitive
Find the last word repitition in a list
lastIndexOf() method, the index of the last occurrence of a particular string can be obtained.
Like this article? Follow @iChuloo on Twitter