Home >>JavaScript String Methods >JavaScript String length Property

JavaScript String length Property

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

Browser Support

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>
Output:

Click the button to see the output.

 


No Sidebar ads