Find the first occurrence of the letter "e" in a string, starting the search at position 5: - Javascript String

Javascript examples for String:indexOf

Description

Find the first occurrence of the letter "e" in a string, starting the search at position 5:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {/*w  w w . ja v a2  s .  c om*/
    var str = "Hello world, welcome to the universe.";
    var n = str.indexOf("e", 5);
    document.getElementById("demo").innerHTML = n;
}
</script>

</body>
</html>

Related Tutorials