JavaScript String length Property
THE WORLD'S LARGEST WEB DEVELOPER SITE

JavaScript String length Property

❮ JavaScript String Reference

Example

Return the number of characters in a string:

var str = "Hello World!";
var n = str.length;
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

❮ JavaScript String Reference