JavaScript_String_Methods
JavaScript_String_Methods
String
Methods
2nd edition
by
Ankush Bhagat
Character Access
1. charAt(index)
Returns the character at a specified index.
2. charCodeAt(index)
Returns the Unicode value of the character at
a specified index.
3. codePointAt(position)
Returns the code point value of the character
at the specified position.
String Comparison
4. localeCompare(string)
Compares two strings in the current locale.
String Searching
5. includes(searchString[, position])
Checks if the string contains the specified
substring
6. indexOf(searchValue[, fromIndex])
Returns the position of the first occurrence of
a specified value.
7. lastIndexOf(searchValue[, fromIndex])
Returns the position of the last occurrence of
a specified value.
8. startsWith(searchString[, position])
Checks if the string starts with the specified
substring.
9. endsWith(searchString[, length])
Checks if the string ends with the specified
substring.
10. match(regexp)
Searches for a match against a regular
expression and returns the matches.
11. matchAll(regexp)
Returns an iterator for all matched groups in
a string.
12. search(regexp)
Executes a search for a match between a
regular expression and the string.
String Modification
22. toLowerCase()
Converts the string to lowercase.
23. toUpperCase()
Converts the string to uppercase.
24. trim()
Removes whitespace from both ends of the
string.
25. trimStart() or trimLeft()
Removes whitespace from the beginning of
the string.
27. normalize([form])
Returns the Unicode normalization form of
the string.
String Encoding and
Decoding
28. toString()
Returns the string representation of an
object.
29. valueOf()
Returns the primitive value of a string object.
Raw String Methods
30. String.raw()
A template string tag that returns the raw
string, escaping backslashes.
Follow
for
more