X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

JavaScript String length Property

JavaScript String Reference JavaScript String Reference

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

Internet Explorer Firefox Opera Google Chrome Safari

The length property is supported in all major browsers.


Syntax

string.length

Technical Details

Return Value: The length of a string
JavaScript Version: 1.0


JavaScript String Reference JavaScript String Reference

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook