Javascript Strings Flashcards
Return the first char of a specified string? Return value?
charAt() returns char at specified index or empty string if index not found
Joins two or more strings? return value?
concat() returns a new string with both strings joined. var str = 'hello'.concat(' world');
Checks whether a string ends with specified string/char? Return value?
endsWith() returns true is string ends with characters, and false if not
Check whether a string contains the string/characters? Return value?
includes() returns true if the string contains the characters, and false if not.
Second parameter can be where to start from (optional) str.includes(“world”, 12)
Returns the position of the first found occurrence of a specified value in a string
indexOf(searchvalue, start) returns a number representing position where the specified searchvalue occurs for the firs time or -1 if not found
Returns the position of the last found occurrence of a specified value in a search string?
lastIndexOf(searchvalue, start) returns a number representing the position where the specified searchvalue occurs else -1
Searches a string for a match against a regular expression?
.match(/ain/g) return array containing the matches, one item for each match or null if no match found
Searches a string for a specified value, or a regular expression, and returns a new string where the specified values are replaced?
.replace(“This”, “That”)
First searchvalue is pattern, second parameter is replacement pattern. Can also take regex .replace(/blue/g, “red”)
Extracts a part of a string and returns a new string?
.slice(1,5) First parameter is required and the position where to begin the extraction. Second parameter is end and optional and the position (up to but not including).
Checks whether a string begins with a specified characters?
.startsWith(“Hello”) method returns true if the string begins with characters else false
Extracts the characters from a string, beginning at a specified start position, and through the specified number of characters?
.substr(1,4) First parameter is the position where to start extraction, second parameter is optional and the number of characters to extract. A new string is returned.
Converts a string to uppercase letters
.toUppderCase()
Converts a string to lowercase?
.toLowerCase()
Removes whitespace from both ends of a string?
.trim
Returns the primitive value of a String object?
.valueOf()