JavaScript lengthProperty

String 对象参考手册JavaScript String Object

Definition and Usage

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

Syntax

string.length


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the length property


Example

Example

Return the number of characters in a string:

<script>

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

</script>

The output of the above example is:

12

Try it Yourself »


String 对象参考手册JavaScript String Object Other Extensions