JavaScript > Strings

String Length in JavaScript

How to find the length of the string in JavaScript?

String Length

String length is nothing but the string character count, that means counting the number of characters in a string and returning the output, that can be generally called as String length, String character count, Characters count in a string etc...

For finding the length of the string we can use the below code.

Returning the lrngth of a string.

    <div id="myId"></div>

        var txt = "Mr. Sheo Narayan is a software professional since 2000 (15+ years) and working in .NET Technologies since its first release. ";
        document.getElementById("myId").innerHTML = txt.length;


In the above code snippet we have text variable with string which is inside in double quotes, and there is document.getElementById("myId") which returns the element that has Id "id=myID" in the HTML page, there is value txt.lenght which calculates the length of the string and gives the output in numerical numbers.


The above output shows the length of the string, that means the number of characters present in that text.

 Views: 2452 | Post Order: 65

Write for us