Strings Flashcards
How do you return the character at a specified index in a string?
charAt(index) - Returns the character at the specified index in a string.
How do you join two or more strings?
concat(string2, string3, …, stringN) - Joins two or more strings and returns a new joined strings.
How do you check if a string contains a specified substring?
includes(searchString, position) - Checks if the string contains a specified searchString, starting at position if given, returning true or false.
How do you find the index of the first occurrence of a specified value in a string?
indexOf(searchValue, fromIndex) - Returns the index of the first occurrence of a specified value in a string, starting the search at fromIndex if provided.
How do you find the index of the last occurrence of a specified value in a string?
lastIndexOf(searchValue, fromIndex) - Returns the index of the last occurrence of a specified value in a string, searching backwards from fromIndex if provided.
How do you replace a specified value with another value in a string?
replace(regexp|substr, newSubstr|function) - Replaces a specified value (regular expression or substring) with another value in a string.
How do you extract a part of a string and return it as a new string?
slice(beginIndex, endIndex) - Extracts a part of a string from beginIndex to endIndex (not inclusive) and returns it as a new string.
How do you split a string into an array of substrings based on a specified separator?
split(separator, limit) - Splits a string into an array of substrings, using a specified separator, and returns the new array.
How do you convert a string to lowercase letters?
toLowerCase() - Converts a string to lowercase letters.
How do you convert a string to uppercase letters?
toUpperCase() - Converts a string to uppercase letters.
How do you remove whitespace from both ends of a string?
trim() - Removes whitespace from both ends of a string.
How do you return the Unicode of the character at a specified index in a string?
charCodeAt(index) - Returns the Unicode of the character at the specified index in a string.
How do you return the character at a specified index, supporting negative indexes to count from the end?
at(index) - Returns the character at the specified index. Negative indexes can be used to count from the end of the string.
How do you extract characters from a string between two specified indices?
substring(indexStart, indexEnd) - Extracts characters from a string between indexStart and indexEnd (not inclusive). Differs from slice in that negative numbers are treated as 0.
How do you extract a specified number of characters from a string, starting at a given index?
substr(start, length) - Extracts a substring from a string, beginning at start and extending for a given length of characters.
How do you return a new string with all matches of a pattern replaced by a replacement?
replaceAll(search, replaceWith) - Returns a new string with all matches of a search pattern (string or regular expression) replaced with replaceWith string.
How do you construct and return a new string which contains the specified number of copies of the string on which it was called, concatenated together?
repeat(count) - Creates a new string consisting of the elements of the calling string repeated count times.
Which methods allow you to pad either the start or end of a string with another string?
padStart(targetLength, padString) and padEnd(targetLength,padString)
Which methods allow you to trim whitespace from either the start or end of a string?
trimStart() and trimEnd()
How do you search a string for a match against a regular expression, and return the matches?
match(regexp) - Searches a string for a match against a regular expression and returns the matches as an Array object.
How do you return an iterator of all results matching a string against a regular expression, including capturing groups?
matchAll(regexp) - Returns an iterator of all matches of the string against a regular expression, including capturing groups.
How do you determine if a string contains a specified substring?
includes(searchString, position) - Determines whether the string includes a specified searchString, starting the search at position if given, returning true or false.
How do you check if a string starts with a specified string or character?
startsWith(searchString, position) - Determines whether a string begins with the characters of a specified searchString, starting the check at position.
How do you check if a string ends with a specified string or character?
endsWith(searchString, length) - Determines whether a string ends with the characters of a specified searchString, considering the string to be of length characters.