Search w3schools.com:

SHARE THIS PAGE

JavaScript length Property

String Object Reference JavaScript String Object

Definition and Usage

The length property returns the length of a string (in characters).

Syntax

string.length


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The length property is supported in all major browsers.


Example

Example

Return the number of characters in a string:

<script>

var txt = "Hello World!";
document.write(txt.length);

</script>

The output of the code above will be:

12

Try it yourself »


String Object Reference JavaScript String Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]