Strings Flashcards
string object
let str = new String();
Object constructor, creates a new String OBJECT. You can still execute string methods on it, but it is considered an object.
string literal
let str = “string”;
The primitive version of a string. When calling methods on this variable, it is autoboxed into a string object.
charAt(index)
returns the character at the specified index
charCodeAt(index)
returns the Unicode of the character at the specified index
concat(string1, string2, …)
concats the passed in strings to the calling string. returns the newly concatted string
endsWith(string OR char)
checks if the calling string ends with the input string or character. returns a boolean
fromCharCode(unicode)
converts the unicode value into a character. returns that character
includes(string OR char)
checks whether a string contains the specified string/characters. returns a boolean
indexOf(any primitive)
returns the first index of the specified value in the calling string
lastIndexOf(any primitive)
returns the position of the last found occurrence of the specified value in the calling string
localeCompare(string)
compares two strings in the current locale. returns either 0, -1, or 1 (though you should simply check for values > or < zero, not specifically -1 & 1)
repeat(number, string)
returns a new string containing the passed in string repeated the passed in number of times
replace(any primitive OR regex, string)
returns a new string with the first occurrence of the primitive value or regex replaced with the passed in string
replaceAll(any primitive OR regex, string)
returns a new string with all of the occurrences of the primitive value or regex replaced with the passed in string
search(any primitive OR regex)
returns the index of the specified primitive or regex. Use this if you are using regex, otherwise indexOf will be the faster version