Latest web development tutorials

JavaScript length property

String Object Reference JavaScript String Object

Definition and Usage

length property returns the string length (number of characters).

grammar

string.length


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support length property


Examples

Examples

Returns the number of characters in the string:

<script>

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

</script>

Examples of the above output:

12

try it"


String Object Reference JavaScript String Object