Javascript programming articles and tutorials for beginner | Anjan Dutta

How to get the length of a string in javascript

How to get the length of a string in javascript

We can get the length of a string in javascript using the string.length property.

The .length property returns the total number of characters in a string.

See the below example code.

var str = 'Hello World';
console.log(str.length);
// > 11

The length of an empty string is 0.

Edit this page on GitHub