Find the first occurrence of the letter "e" in a string: - Javascript String

Javascript examples for String:indexOf

Description

Find the first occurrence of the letter "e" in a string:

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  va2  s  .c  o m*/
    var str = "Hello world, welcome to the universe.";
    var n = str.indexOf("e");
    document.getElementById("demo").innerHTML = n;
}
</script>

</body>
</html>

Related Tutorials