# The String lastIndexOf() method

> Learn how the JavaScript lastIndexOf() method returns the position of the last occurrence of a substring inside a string, or -1 when the value is not found.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2019-02-21 | Topics: [JavaScript](https://flaviocopes.com/tags/js/) | Canonical: https://flaviocopes.com/javascript-string-lastindexof/

Gives the position of the last occurrence of the string passed as parameter in the current string.

Returns `-1` if the search string is not found.

```js
'JavaScript is a great language. Yes I mean JavaScript'.lastIndexOf('Script') //47
'JavaScript'.lastIndexOf('C++') //-1
```

Also see [`indexOf()`](https://flaviocopes.com/javascript-string-indexof/).
