Javascript examples for String:length
The length property returns the length of number of characters.
The length of an empty string is 0.
The length of a string
The following code shows how to return the number of characters in a string:
<!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>