JavaScript String length Property
Example
Return the number of characters in a string:
var str = "Hello World!";
var n = str.length;
The result of n will be:
12
Try it Yourself »
Definition and Usage
The length property returns the length of a string (number of characters).
The length of an empty string is 0.
Browser Support
Property | |||||
---|---|---|---|---|---|
length | Yes | Yes | Yes | Yes | Yes |
Syntax
string.length
Technical Details
Return Value: | The length of a string |
---|---|
JavaScript Version: | 1.0 |
