JS-String Methods
From MDN.
Method | Purpose | |
String() |
Creates a new String object. It performs type conversion when called as a function, rather than as a constructor, which is usually more useful. |
|
.length | Reflects the length of the string. Read-only. | |
.at() |
Returns the character (exactly one UTF-16 code unit) at the specified index. Accepts negative integers, which count back from the last string character. |
|
.charAt() | Returns the character (exactly one UTF-16 code unit) at the specified index. | |
.charCodeAt() | Returns a number that is the UTF-16 code unit value at the given index. | |
.codePointAt() |
Returns a nonnegative integer Number that is the code point value of the UTF-16 encoded code point starting at the specified pos. |
|
.concat() | Combines the text of two (or more) strings and returns a new | |
.includes() | Determines whether the calling string contains search | |
.endsWith() | Determines whether a string ends with the characters of the string search | |
.indexOf() | Returns the index within the calling String object of the first occurrence of searchValue, or -1 if not found. | |
.lastIndexOf() | Returns the index within the calling String object of the last occurrence of searchValue, or -1 if not found. | |
.localeCompare() |
Returns a number indicating whether the reference string compareString comes before, after, or is equivalent to the given string in sort order. |
|
.match() | Used to match regular expression regexp against a | |
.matchAll() | Returns an iterator of all regexp’s matches. | |
.normalize() | Returns the Unicode Normalization Form of the calling string value. | |
.padEnd() | Pads the current string from the end with a given string and returns a new string of the length targetLength. | |
.padStart() | Pads the current string from the start with a given string and returns a new string of the length targetLength. | |
.repeat() | Returns a string consisting of the elements of the object repeated count times. | |
.replace() |
Used to replace occurrences of searchFor using replaceWith. searchFor may be a string or Regular Expression, and replaceWith may be a string or function. |
|
.replaceAll() |
Used to replace all occurrences of searchFor using replaceWith. searchFor may be a string or Regular Expression, and replaceWith may be a string or function. |
|
.search() | Search for a match between a regular expression regexp and the calling | |
.slice() | Extracts a section of a string and returns a new | |
.split() | Returns an array of strings populated by splitting the calling string at occurrences of the substring sep. | |
.startsWith() | Determines whether the calling string begins with the characters of string search | |
.substring() |
Returns a new string containing characters of the calling string from (or between) the specified index (or indices). |
|
.toLocaleLowerCase() |
The characters within a string are converted to lowercase while respecting the current locale. For most languages, this will return the same as toLowerCase() |
. |
.toLocaleUpperCase( [locale, …locales]) |
The characters within a string are converted to uppercase while respecting the current locale. For most languages, this will return the same as toUpperCase() |
|
.toLowerCase() | Returns the calling string value converted to lowercase. | |
.toString() | Returns a string representing the specified object. Overrides the Object.prototype.toString() | |
.toUpperCase() | Returns the calling string value converted to uppercase. | |
.trim() | Trims whitespace from the beginning and end of the | |
.trimStart() | Trims whitespace from the beginning of the | |
.trimEnd() | Trims whitespace from the end of the | |
.valueOf() | Returns the primitive value of the specified object. Overrides the Object.prototype.valueOf() |