Strings Flashcards
length()
Returns the length of the string
* PROPERTY, NOT A METHOD
* Counts code units, not characters
*
The length of the string
String.length()
charAt()
New string of single UTF-16 code unit @ pecified offset into the string
* charAt(index)
* if index is out of range, returns empty string
String representing the character @ index
String.prototype.charAt()
concat()
Concatenates N number of strings
* concat(strN)
* Converts elements into string values
* concat() coerces its arguments directly to strings (while + coerces to primitives first)
*
New string containing the combined text of the strings provided
String.prototype.concat()
indexOf()
Returns the index of the first occurrence of a specified substring in the string, or -1 if not present
* indexOf(searchString, position)
* searchString
is the substring that is searched within the called string
* Case sensitive!
Index of the first occurrence of searchString
String.prototype.indexOf()
lastIndexOf()
Returns the index of the last occurrence of a specified substring in the string, or -1 if not found.
* lastIndexOf(searchString, position)
* Case sensitive!
The index of the last occurrence of searchString
found, if not, -1
Array.prototype.lastIndexOf()
replace()
Replaces a specified substring with another string
* String pattern will only be replaced once
New string w/ N matches of the pattern replaced by specified replacement
String.prototype.replace(pattern, replacement)
slice()
Returns a portion of the string
* Extracts up to, but not including indexEnd
*
A new string containing the extracted section of the string
String.prototype.slice(indexStart, indexEnd)
split()
Splits the string into an array of substrings based on specified separator
* if separator
is undefined, target string is returned wrapped in an array
An Array of strings, split @ each point separator
occurs in the string
String.prototype.split(separator, limit )
substring()
Returns a substring between two specified indexes
* extracts characters from indexStart
up to not including indexEnd
A new string containing the specified part of the given string
String.prototype.substring(indexStart, indexEnd)
toLowerCase()
Converts the string to lowercase
* Non-mutating method
* Does not affect the value of str
itself
A new string representing the calling string converted to lower case
String.prototype.toLowerCase()
toUpperCase()
Converts the string to uppercase
* Non-mutating method
* Does not affect the value of str
itself
A new string representing the calling string converted to upper case
String.prototype.toUpperCase()
trim()
Removes whitespace from the beginning and end of the string
* if there is no whitespace, essentially coppies str
* For more options, use trimStart()
or trimEnd()
New string stripped of whitespace from both beginning and end
String.prototype.trim()