String length Property - Javascript String

Javascript examples for String:length

Description

The length property returns the length of number of characters.

The length of an empty string is 0.

Return Value:

The length of a string

The following code shows how to return the number of characters in a string:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from   w  w w.  ja  v a  2s  . c o m*/
    var str = "Hello World!";
    var n = str.length;
    document.getElementById("demo").innerHTML = n;
}
</script>

</body>
</html>

Related Tutorials