length (JavaScript)
Gets the length of a string.
Defined in
String (Standard - JavaScript)Syntax
length() : int
Return value | Description |
---|---|
int |
The number of characters in the string. |
Usage
The index of the last character in the string is the length of the string minus 1.Examples
This example returns the bracketed numeric codes for the characters in the string.var cities = new String("Paris Moscow Tokyo");
var codes = "";
for(var i=0; i<cities.length(); i++) {
codes = codes + "[" + cities.charCodeAt(i) + "]";
}
return codes