String methods
Provides a reference for string methods.
Characters in a string are indexed from left to right. The index
of the first character in a string is 0, and the index of the last
character is string.length-1.
| Syntax | Effect |
|---|---|
| string.substring(start [ , end ] ) | Returns the substring of Examples: "0123456".substring(0, 3) –> "012" "0123456".substring(2, 4) –> "23" "0123456".substring(2) –> "23456" |
| string.charAt(index) | Returns a one-character string containing the character
at the specified index of string. If Examples: "abcdef".charAt(0) –> "a" "abcdef".charAt(3) –> "d" "abcdef".charAt(100) –> "" |
| string.charCodeAt(index) | Returns the ASCII code of the character at the specified
index of Examples: "abcdef".charCodeAt(0) –> 97 "abcdef".charCodeAt(3) –> 100 "abcdef".charCodeAt(100) –> NaN |
| string.indexOf(substring [ , index ] ) | Returns the index in Examples: "abcdabcd".indexOf("bc") –> 1 "abcdabcd".indexOf("bc", 1) –> 1 "abcdabcd".indexOf("bc", 2) –> 5 "abcdabcd".indexOf("bc", 10) –> -1 "abcdabcd".indexOf("foo") –> -1 "abcdabcd".indexOf("BC") –> -1 |
| string.lastIndexOf(substring [ , index ] ) | Returns the index in Examples: "abcdabcd".lastIndexOf("bc") –> 5 "abcdabcd".lastIndexOf("bc", 5) –> 5 "abcdabcd".lastIndexOf("bc", 4) –> 1 "abcdabcd".lastIndexOf("bc", 0) –> -1 "abcdabcd".lastIndexOf("foo") –> -1 "abcdabcd".lastIndexOf("BC") –> -1 |
| string.toLowerCase() | Returns Example: "Hello, World".toLowerCase() "hello, world" |
| string.toUpperCase() | string.toUpperCase() Returns Example: "Hello, World".toUpperCase() "HELLO, WORLD" |
| string.split(separator) | Returns an array of strings containing the substrings of Examples: " If Example:
|
| string.toString() | Returns the string itself. |