String Methods Flashcards
operation performed on strings, including theconcatmethod, results in…
a new string
Concat can take ________ as arguments. it returns______
more than one strings.
all those strings combined into one
String.prototype.includes()
- The
includes
method takes a string as the argument and returns a boolean signifying whether that string exists within the string thatincludes
was called on. -
includes
also takes an optional second argument that specifies which index in the string to start looking for the substring.
String.prototype.trim()
- The
trim
method removes whitespace from both ends of the string it’s called on. - The
trim
method is often useful when getting input from users, which can often contain unnecessary whitespace at either end. -
trim
removes any number of space characters as well as whitespace characters like\n
and\t
.
String.prototype.charAt
ThecharAtmethod is nearly identical to using brackets on a string. It takes an index as an argument and returns the character at that index in the given string
The chief difference betweencharAtand[]occurs when using indices for characters that don’t exist:charAtreturns an empty string (‘’), while[]returns undefined:
String.prototype.charCodeAt
- The method
charCodeAt
is similar tocharAt
, but instead of returning the character at the given index, it returns theUnicode code pointorcharacter codeof the character at that index. - A Unicode code point is the number that represents a given character at the machine level.
- If you don’t provide an index,
charCodeAt
assumes the index0
.
String.fromCharCode
- The
String.fromCharCode
method does the opposite ofString.prototype.charCodeAt
. It takes a character code (Unicode code point) and returns the character represented by that character code. - Note that
fromCharCode
is not a prototype method. It’s instead what we call astatic methodor a function. It can only be called from the string constructor
String.prototype.endsWith()
- Returns a boolean represenign if the calling string ends with the passed string. The string argument cant be a regEx.
- omitting the argument or passing
undefined
causesendsWith()
to search for the string"undefined"
, which is rarely what you want. - optional endposition argument if you don’t want the ending position to be str.length
String.prototype.startsWith()
Same as endsWith but for starting position
String.prototype.repeat()
- Therepeat() method ofString constructs and returns a new string which contains the specified number of copies of this string, concatenated together.