MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › lastIndexOf
String.prototype.lastIndexOf() - JavaScript | MDN
'hello world hello'.lastIndexOf('hello', 99) returns 12 — because the last occurrence of hello at a position less than or equal to 99 is at position 12.
W3Schools
w3schools.com › jsref › jsref_lastindexof.asp
JavaScript String lastIndexOf() Method
The lastIndexOf() method returns the index from the beginning (position 0).
W3Schools
w3schools.com › java › ref_string_lastindexof.asp
Java String lastIndexOf() Method
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate ... String myStr = "Hello planet earth, you are a great planet."; System.out...
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › lastIndexOf
Array.prototype.lastIndexOf() - JavaScript | MDN
The lastIndexOf() method of Array instances returns the last index at which a given element can be found in the array, or -1 if it is not present. The array is searched backwards, starting at fromIndex.
Javatpoint
javatpoint.com › java-string-lastindexof
Java String lastIndexOf() method - javatpoint
Java String lastIndexOf() method with method signature and examples of concat, compare, touppercase, tolowercase, trim, length, equals, split, string lastindexof in java etc.
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › system.collections.generic.list-1.lastindexof
List .LastIndexOf Method (System.Collections.Generic) | Microsoft Learn
Finally, the LastIndexOf(T, Int32, Int32) method overload is used to search a range of four entries, beginning at index location 4 and extending backward (that is, it searches the items at locations 4, 3, 2, and 1); this search returns -1 because ...
Dot Net Perls
dotnetperls.com › lastindexof
C# - String LastIndexOf Examples - Dot Net Perls
Tip When we call LastIndexOfAny, we must provide a character array. This can be created directly in the argument slot. Here The example searches for the first instance of a "d" or "b" character starting from the end of the string.
Programiz
programiz.com › csharp-programming › library › string › lastindexof
C# String LastIndexOf() (With Examples)
int index = str.LastIndexOf('c', 2); Console.WriteLine(index); Console.ReadLine(); } } }
BeginnersBook
beginnersbook.com › 2013 › 12 › java-string-lastindexof-method-example
Java String lastIndexOf() Method with example
int lastIndexOf(String str, int fromIndex): Returns the last occurrence of str, starts searching backward from the specified index “fromIndex”. In the following example we are searching few given characters and a given substring in the String str. We are looking for their last occurrence ...
Codecademy
codecademy.com › docs › java › strings › .lastindexof()
Java | Strings | .lastIndexOf() | Codecademy
March 2, 2023 - This example below searches the ... static void main(String[] args) { String sentence = "The quick brown fox jumps over the lazy dog"; int lastPos = sentence.lastIndexOf("the"); System.out.println(lastPos); } } Copy to ...
Top answer 1 of 5
16
From MDN :
The indexOf() method returns the index within the calling String object of the first occurrence of the specified value, The lastIndexOf() method returns the index within the calling String object of the last occurrence of the specified value
So the indexOf will return first occurrence of the value and the lastIndexOf will return the last occurence of the value.
Example (copied from MDN):
var anyString = "Brave new world";
var a = anyString.indexOf("w")); // result = 8
var b = anyString.lastIndexOf("w")); // result 10
Both of the method return -1 if the value is not found
More :
- indexOf
- lastIndexOf
2 of 5
5
string.indexOf() method returns the position of the first occurrence of a specified value in a string.
string.lastIndexOf() method returns the position of the last occurrence of a specified value in a string.
JavaScript Tutorial
javascripttutorial.net › home › javascript string methods › string.prototype.lastindexof()
JavaScript String lastIndexOf() Method
November 3, 2024 - In this tutorial, you'll learn how to use the JavaScript String lastIndexOf() method to locate the last occurrence of a substring in a string.
Wavefront
docs.wavefront.com › ts_indexof.html
indexOf and lastIndexOf Functions | VMware Aria Operations for Applications Documentation
indexOf(metric|source|<pointTagKey>, "<subString>", <tsExpression>) lastIndexOf(metric|source|<pointTagKey>, "<subString>", <tsExpression>)
MuleSoft
docs.mulesoft.com › dataweave › latest › dw-core-functions-lastindexof
lastIndexOf | MuleSoft Documentation
%dw 2.0 output application/json ... } { "present": 2, "notPresent": -1, "presentMoreThanOnce": 3 } Takes a string as input and returns the index of the last occurrence of a given search string within the input....
Programiz
programiz.com › javascript › library › string › lastindexof
JavaScript String lastIndexOf() (With Examples)
// find last occurrence of "m" in str var result = str.lastIndexOf(substr); console.log(result); ... In the above example, we have defined a string named str.
Codecademy
codecademy.com › docs › javascript › strings › .lastindexof()
JavaScript | Strings | .lastIndexOf() | Codecademy
November 24, 2025 - If the substring isn’t found, ... name, and the method finds the last one: const message = 'Hey Sam, Sam, are you coming to the meeting, Sam?'; const lastSam = message.lastIndexOf('Sam'); console.log(lastSam); Copy to ...
C-sharptutorial
c-sharptutorial.com › string › lastindexof-in-csharp
C# LastIndexOf()
LastIndexOf() is public built-in method which mean it can be accessible anywhere in code with string class. String.LastIndexOf() method is used to search for the last occurrence of a specified substring and returns its index. In below example, we have string with named s1 which have value Cherry.