Search This Blog

Thursday, 28 July 2016

How to find the specific word in given paragram using javascript?

Html  Page:

<button onclick="myFunction()">Try it</button>
<p id="demo"></p>

Javascript Page:

<script>
function myFunction()
{
    var str = "Hello world, welcome to the universe.";
    var n = str.indexOf("welcome");
    document.getElementById("demo").innerHTML = n;
}
</script>

Output:

13

No comments:

Post a Comment