JS String Flashcards
How can you access a character in a string?
A) ‘dog’.charAt(1) // “o”
B) ‘dog’[2] // “g”
How can primitive strings use methods of the object String without the ‘new’ keyword?
JavaScript will automatically wrap the string primitive and call the method or perform the property lookup on the wrapper object instead.
\0
Escape sequence null character (U+0000 NULL)
' " \
Escape sequences
single quote (U+0027 APOSTROPHE)
double quote (U+0022 QUOTATION MARK)\
backslash (U+005C REVERSE SOLIDUS)
\n \r \b
Escape sequences
newline (U+000A LINE FEED; LF)
carriage return (U+000D CARRIAGE RETURN; CR)
backspace (U+0008 BACKSPACE)
\v \t \f
Escape sequences
backslash vertical tab (U+000B LINE TABULATION)
tab (U+0009 CHARACTER TABULATION)
form feed (U+000C FORM FEED)
\uXXXX
escape sequence
Unicode code point between U+0000 and U+FFFF
(the Unicode Basic Multilingual Plane)
String.prototype.length
a read only property, returns the length of the string
String.prototype.charAt(index)
String.prototype.charCodeAt(index)
String.prototype.indexOf(searchValue [, fromIndex])
String.prototype.lastIndexOf(searchValue [, fromIndex])
Returns the character (exactly one UTF-16 code unit) at the specified index.
Returns a number that is the UTF-16 code unit value at the given index.
Returns the index within the calling String object of the first occurrence of searchValue, or -1 if not found.
Returns the index within the calling String object of the last occurrence of searchValue, or -1 if not found.
String.prototype.concat(str [, …strN ])
Combines the text of two (or more) strings and returns a new string.
String.prototype.includes(searchString [, position])
String.prototype.endsWith(searchString [, length])
String.prototype.startsWith(searchString [, length])
Determines whether the calling string contains searchString.
Determines whether a string ends with the characters of the string searchString.
Determines whether the calling string begins with the characters of string searchString.
String.prototype.localeCompare(compareString [, locales [, options]])
Returns a number indicating whether the reference string compareString comes before, after, or is equivalent to the given string in sort order.
String.prototype.matchAll(regexp)
String.prototype.match(regexp)
String.prototype.search(regexp)
Returns an iterator of all regexp’s matches.
Used to match regular expression regexp against a string.
Search for a match between a regular expression regexp and the calling string.
String.prototype.padEnd(targetLength [, padString])
String.prototype.padStart(targetLength [, padString])
Pads the current string from the end || start with a given string and returns a new string of the length targetLength.
String.prototype.repeat(count)
Returns a string consisting of the elements of the object repeated count times.