JavaScript – String Length
To get length of a string in JavaScript, read the length property of the string instance.
Syntax
The syntax to read length property of a string instance str
is
str.length
ADVERTISEMENT
Examples
The following is a quick example to get the length of a string in JavaScript.
var str = 'hello world'; var len = str.length;
In the following example, we take a string str
in script, and find its length. We shall display the string length in a div.
index.html
Conclusion
In this JavaScript Tutorial, we learned how to get the length of a string in JavaScript, using length property, with examples.