JavaScript String lastIndexOf() methodThe JavaScript string lastIndexOf() method is used to search the position of a particular character or string in a sequence of given char values. It behaves similar to indexOf() method with a difference that it start searching an element from the last position of the string. The lastIndexOf() method is case-sensitive. The index position of first character in a string is always starts with zero. If an element is not present in a string, it returns -1. SyntaxThese are the following ways used to search the position of an element.
Parametersch - It represent the single character to search like 'a'. index - It represent the index position from where search starts. str - It represent the string to search like "Java". JavaScript String lastIndexOf() method exampleLet's see the various ways of searching the position of an element with help of simple examples. Example 1Here, we will print the position of a single character. Test it NowOutput: 23 Example 2In this example, we will provide the index value from where the search starts. Test it NowOutput: 21 Example 3Here, we will print the position of a first character of string. Test it NowOutput: 20 Example 4In this example, we will provide the index value from where the search starts. Test it NowOutput: 6 Example 5Here, we will try to search the element by changing its case-sensitivity. Test it NowOutput: -1 Next TopicJavaScript String |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India