String_Methods Flashcards
string.length
find length of string
string[index]
Retrieving character from string
string.includes(“zilla”)
Testing if a string contains a substring (eg “zilla” in “mozilla” will retunr true)
string.startsWith(“abc”)
Want to know whether string starts with specific substring (in this case “abc”)
string.endsWith(“abc”)
Want to know whether string end with a specific substring (in this case “abc”)
string.indexOf()
Finding position of a substring in a string. Returns index of first occurrence of the substring. Return -1 if not present.
string.slice(index, index)
extracts substring from a string. Only one index required if you want to extract all characters after a certain letter. 2 indexes required if you want from a certain index to another index.
string.toLowerCase()
convert string to lowercase
string.toUpperCase()
convert string to uppercase
string.replace(“abc”, “def”)
first parameter is substring you want to replace, second parameter is what you want to replace substring with.
string.replaceAll(“be”, “code”)
Replace all occurrences of “be” by “for”