length |
|
Returns the number of characters in a string |
substring() |
str.substring(indexStart, indexEnd)
|
Returns a specified part of the string |
slice() |
str.slice(beginIndex, endIndex)
|
Extracts and returns a section of the string |
substr() |
str.substr(beginIndex, length)
|
similar to slice()
, but the second parameter specifies the length of the extracted part. |
replace() |
str.replace(pattern, replacement)
|
replace a substring/pattern in the string |
replaceAll() |
str.replaceAll(pattern, replacement)
|
Returns string by replacing all matching patterns |
toUpperCase() toLowerCase() |
str.toUpperCase() str.toLowerCase()
|
Returns uppercase/lowercase representation of a string |
concat() |
str.concat(str1, ..., strN)
|
Concatenates the arguments to the calling string |
~repeat() |
|
Returns a string by repeating it given times |
trim() |
|
Removes whitespace from both ends of a string |
padStart() padEnd() |
str.padStart(targetLength, padString) str.padEnd(targetLength, padString)
|
Pads a string at the start/end to a given length |
charAt() |
|
Returns character at a specified index in string |
charCodeAt() |
str.charCodeAt(index)
|
Returns Unicode of the character at given index |
~fromCharCode() |
String.fromCharCode(num1, ..., numN)
|
Returns a string from the given UTF-16 code units |
~codePointAt() |
|
Returns the Unicode point value at given index |
~fromCodePoint() |
String.fromCodePoint(num1, ..., numN)
|
Returns a string using the given code points |
split() |
str.split(separator, limit)
|
Returns the string divided into list of substring |
- - Search Methods - - |
indexOf() lastIndexOf() |
str.indexOf(searchValue, fromIndex) str.lastIndexOf(searchValue, fromIndex)
|
Returns the first index/last index of occurrence of a value |
search() |
|
Searches for specified value in the string |
match() |
|
Returns result of matching string with a regex |
matchAll() |
|
Returns iterator of results matching with a regex |
includes() |
str.includes(searchString, position)
|
Checks if given string is found inside a string |
startsWith() endsWith() |
str.startsWith(searchString, position) str.endsWith(searchString, length)
|
Checks if a string begins/ends with a specified string |
localeCompare() |
str.localeCompare(compareStr, locales, options)
|
Compares two strings in the current locale |
- - Template Literals - - ${...}
|
Template literals provide an easy way to interpolate variables and expressions into strings. |