lastIndexOf()




Il lastIndexOf()metodo ricerca all'indietro (dalla fine all'inizio), ovvero: se il secondo parametro e' 15, la ricerca inizia dalla posizione 15 e cerca fino all'inizio della stringa.

Esempio
var str = "Please locate where 'locate' occurs!";
var pos = str.lastIndexOf("locate", 15);

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript String Methods</h2>

<p>The lastIndexOf() method accepts a second parameter as the starting position for the search.</p>
<p>Remember that the lastIndexOf() method searches backwards, so position 15 means start the search at position 15, and search to the beginning.</p>
<p>Position 15 is position 15 from the beginning.</p>

<p id="demo"></p>

<script>
var str = "Please locate where 'locate' occurs!";
var pos = str.lastIndexOf("locate", 15);
document.getElementById("demo").innerHTML = pos;
</script>

</body>
</html>











( lastindexof.html )- by Paolo Puglisi - Modifica del 17/12/2023