Search This Blog

Wednesday, 27 July 2016

How to get string length using javascript?

Html page:

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

JavaScript page:

<script>
function myFunction() {
    var str = "Hello World!";
    var n = str.length;
    document.getElementById("demo").innerHTML = n;
}
</script>

Output:
12

No comments:

Post a Comment