Home >>JavaScript String Methods >JavaScript String length Property
JavaScript length property is used to return the length of a given input string. The length is calculated on the basis of number of characters present in the string. If the given string is an empty string then it’s length will be 0.
Syntax:
string.length
Property | Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
length | Yes | Yes | Yes | Yes | Yes |
Here is an example of length property:
<html> <body> <p>Click the button to see the output.</p> <button onclick="myFunction()">Try it</button> <p id="demo"</p> <script> function myFunction() { var str = "PHPTPOINT"; var n = str.length; document.getElementById("demo").innerHTML = n; } </script> </body> </html>
Click the button to see the output.