EN
JavaScript - String lastIndexOf() method example
0
points
// ONLINE-RUNNER:browser;
const text = 'ABC ABC';
console.log(text.lastIndexOf('A')); // 4
console.log(text.lastIndexOf('B')); // 5
console.log(text.lastIndexOf('C')); // 6
console.log(text.lastIndexOf('X')); // -1
console.log(text.lastIndexOf('ABC')); // 4
console.log(text.lastIndexOf('XYZ')); // -1
console.log(text.lastIndexOf('B', 2)); // 1
console.log(text.lastIndexOf('B', 6)); // 5
1. Documentation
Syntax |
|
Parameters |
|
Result | The method returns the index of the last occurrence of searchString or -1 if not found. |
Description |
The If the second argument is given (a number), the method returns the last occurrence of the specified substring at an index less than or equal to the specified number. |