String Properties and Methods

Properties

myString contains "".

Property Explanation Code Returns
length Read-only value containing the number of characters in the string. myString.length

Methods

myString contains "".

Method Explanation Code Returns
charAt(position) Returns the character at the specified position. myString.charAt(4)
charCodeAt(position) Returns the Unicode character code of the character at the specified position. myString.charCodeAt(4)
fromCharCode(characterCodes) Returns the text representation of the specifies comma-delimited character codes. Used with String rather than a specific String object. String.fromCharCode(169)
indexOf(substring, startPosition) Searches from startPosition for substring. Returns the position at which the substring is found. If substring is not found, returns -1. myString.indexOf("cat")
myString.indexOf("cat", 5)
lastIndexOf(substring, endPosition) Searches from the end of the string for substring until endPosition is reached. Returns the position at which the substring is found. If substring is not found, returns -1. myString.lastIndexOf("cat")
myString.lastIndexOf("cat", 5)
substring(startPosition, endPosition) Returns the substring beginning at startPosition and ending with the character before endPosition. endPosition is optional. If it is excluded, the substring continues to the end of the string. myString.substring(4, 7)
myString.substring(4)
substr(startPosition, length) Returns the substring of length characters beginning at startPosition. length is optional. If it is excluded, the substring continues to the end of the string. myString.substr(4, 3)
myString.substr(4)
slice(startPosition, endPosition) If End Position is positive, same as substring(startPosition, endPosition). myString.slice(4, 7)
slice(startPosition, positionFromEnd) If positionFromEnd is negative, returns the the substring beginning at startPosition and ending positionFromEnd characters from the end of the string. myString.slice(4, -2)
split(delimiter) Returns an array by splitting a string on the specified delimiter. var S = "A,B,C,D";
var A = S.split(",");
document.write(A[2]);
toLowerCase() Returns the string in all lowercase letters. myString.toLowerCase()
toUpperCase() Returns the string in all uppercase letters. myString.toUpperCase()