String Flashcards
String.fromCharCode()
params: (num1[, …[, numN]])
num1, …, numN
A sequence of numbers that are Unicode values.
Returns a string created by using the specified sequence of Unicode values.
Note: Because fromCharCode() is a static method of String, you always use it as String.fromCharCode(), rather than as a method of a String object you created.
String.fromCodePoint()
params: (num1[, …[, numN]])
num1, …, numN
A sequence of code points.
Returns a string created by using the specified sequence of code points.
Note: Because fromCodePoint() is a static method of String, you always use it as String.fromCodePoint(), rather than as a method of a String object you created.
String.prototype.anchor()
params: (name)
name
The name attribute string
Creates an <a> HTML anchor element that is used as a hypertext target.</a>
Example
document.body.innerHTML = myString.anchor(‘contents_anchor’);</a>
String.prototype.charAt()
params: (index)
index
The index of the character, 0 to .length-1
Returns character at that index
String.prototype.charCodeAt()
params: (index)
index
The index of the character, 0 to .length-1
Returns numeric Unicode value of the character at the given index (except for unicode codepoints > 0x10000).
String.prototype.codePointAt()
params: (pos)
pos
Position of an element in the String to return the code point value from.
Returns the UTF-16 encoded code point value.
Example
‘\uD800\uDC00’.codePointAt(0); // 65536
String.prototype.concat()
params: (string2, string3[, …, stringN])
string2…stringN
Strings to concatenate to this string.
Combines the text of the strings and returns a new string.
Note: + performs better
String.prototype.endsWith()
params: (searchString[, position])
searchString
The characters to be searched for at the end of this string.
position
Optional. Search within this string as if this string were only this long; defaults to this string’s actual length, clamped within the range established by this string’s length.
Determines whether a string ends with the characters of another string
String.prototype.includes()
params: (searchString[, position])
searchString
The characters to be searched for within this string.
position
Optional. The position in this string at which to begin searching for searchString; defaults to 0.
Determines whether one string may be found within another string
String.prototype.indexOf()
params: (searchValue[, fromIndex])
searchValue
String to search for.
fromIndex Optional
The location within the calling string to start the search from.
Returns the index within the calling String object of the first occurrence of searchValue, starting the search at fromIndex. Returns -1 if the value is not found.
String.prototype.lastIndexOf()
params: (searchValue[, fromIndex])
searchValue
Value to search for
fromIndex
Where to start searching. If negative, it is treated as 0. If fromIndex > str.length, fromIndex is treated as str.length.
Returns last index, or -1 if not found
String.prototype.link()
params: (url)
url
An escaped URL string
Creates a link
String.prototype.localeCompare()
params: (compareString[, locales[, options]])
Returns -1 if given string comes before reference string, 0 if they are the same place, and 1 if it comes after.
String.prototype.match()
params: (regexp)
regexp
A regular expression object or something that can be coerced to regex
Returns an array of matches
Note: If the regular expression does not include the g flag, returns the same result as RegExp.exec(). Also does not return capture groups.
String.prototype.normalize()
params: ([form])
form
One of “NFC”, “NFD”, “NFKC”, or “NFKD”
String.prototype.repeat()
params: (count)
Returns the given string repeated $count times
String.prototype.replace()
params: (regexp|substr, newSubStr|function[, flags])
regexp (pattern)
A RegExp object. The match is replaced by the return value of parameter #2.
substr (pattern)
newSubStr (replacement)
The String that replaces the substring received from parameters. A number of special replacement patterns are supported
function (replacement)
A function to be invoked to create the new substring (to put in place of the substring received from parameter).
Returns a string with all matches of the pattern replaced.
String.prototype.search()
params: (regexp)
regexp
A RegExp object.
Searches for match between string and RegExp. If found, returns index of first match. If not, returns -1
Note: faster than match for simple check
String.prototype.slice()
params: (beginSlice[, endSlice])
beginSlice
index to start at. if negative, moves rtl from end
endSlice
index where to end extraction
Extracts and returns a string
String.prototype.split()
params: ([separator[, limit]])
separator
characters to separate on.
limit
number of splits to be found. still splits every match, but truncates the array
splits a string into an array of strings
String.prototype.startsWith()
params: (searchString[, position])
searchString
string to be searched for
position
the position to start from
Returns true if string starts with searchString, false otherwise
String.prototype.substr()
params: (start[, length])
start
index to start at. if negative, rtl from end of string
length
number of characters to extract
Returns string starting at index going for length.
String.prototype.substring
params: (indexStart[, indexEnd])
indexStart
index to start at
indexEnd
index to end at
Returns the substring between the two indexes, exclusive of indexEnd
String.prototype.toLocaleLowerCase()
String.prototype.toLocaleUpperCase()
returns the value to lower or uppercase in the host environment’s locale
String.prototype.toLowerCase()
String.prototype.toUpperCase()
returns upper/lower case
String.prototype.toString()
overrides the Object.prototype.toString(). Same as valueOf()
String.prototype.trim()
Return a string with whitespace removed at either end
String.prototype@@iterator
Returns a new iterator over the code points
Use with for..of
Example 1
for (var val of str)
Example 2
var strIter = stringSymbol.iterator;
console.log(strIter.next().value); // “A”
String.rawHi${name}
Unprocessed template string, but with substitutions made
Example
String.rawHi${name}