Search This Blog

Friday, 29 July 2016

How to display the extracted part of the string using javascript?

Html page:

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

Javascript page:

<script>
    function myFunction() {
        var str = "Hello world!";
        var res = str.slice(1, 5);
        document.getElementById("demo").innerHTML = res;
    }
</script>

Output:

ello

No comments:

Post a Comment