JavaScript lengthProperty
JavaScript String Object
Definition and Usage
The length property returns the length of a string (number of characters).
Syntax
string.length
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the length property
Example
Example
Return the number of characters in a string:
<script>
var txt = "Hello World!";
document.write(txt.length);
</script>
var txt = "Hello World!";
document.write(txt.length);
</script>
The output of the above example is:
12
Try it Yourself »
JavaScript String Object Other Extensions