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.