JavaScript (ES2026) reference · 36 entries
JavaScript String Methods
Every JavaScript string method, from at() to trimEnd(), with syntax, parameters, the ECMAScript edition that added it, and examples you can run.
Strings are immutable: every method returns a new string and leaves the original unchanged. Lengths and indexes
count UTF-16 code units, so an emoji can count as 2; use [...str] or for…of to work with whole characters.
| Name | Description | Since |
|---|---|---|
string.at() |
Return the character at an index, where negative indexes count from the end: str.at(-1) is the last character. | ES2022 |
string.charAt() |
Return the character at a given index as a new string, or an empty string if the index is out of range. | ES1 |
string.charCodeAt() |
Return the UTF-16 code unit (0 to 65535) at an index. For emoji and other astral characters use codePointAt(). | ES1 |
string.codePointAt() |
Return the full Unicode code point at an index, correctly handling emoji and other characters outside the BMP. | ES2015 |
string.concat() |
Join one or more strings to the end of this string and return the result. The + operator and template literals are more common. | ES3 |
string.endsWith() |
Return true if the string ends with the given text. Case-sensitive; an optional length treats the string as shorter. | ES2015 |
string.includes() |
Return true if the string contains the given text anywhere. Case-sensitive. | ES2015 |
string.indexOf() |
Return the index of the first occurrence of some text, or -1 if it isn't found. | ES1 |
string.isWellFormed() |
Return true if the string has no lone surrogates, i.e. it can be safely encoded as UTF-8. | ES2024 |
string.lastIndexOf() |
Return the index of the last occurrence of some text, searching backwards, or -1 if it isn't found. | ES1 |
string.length |
The number of UTF-16 code units in the string, which is more than the number of characters for emoji. | ES1 |
string.localeCompare() |
Compare two strings using language rules; returns a negative number, 0 or a positive number. Use it to sort names. | ES3 |
string.match() |
Match the string against a regular expression and return the matches (all of them with the g flag) or null. | ES3 |
string.matchAll() |
Return an iterator of every regular-expression match, including capture groups. The regex must have the g flag. | ES2020 |
string.normalize() |
Return the Unicode normalization form of a string so visually identical text compares equal (NFC, NFD, NFKC, NFKD). | ES2015 |
string.padEnd() |
Pad the end of a string with another string until it reaches a target length. Useful for aligned text columns. | ES2017 |
string.padStart() |
Pad the start of a string until it reaches a target length, for example zero-padding numbers like 007. | ES2017 |
string.repeat() |
Return a new string made of this string repeated a given number of times, for example to build separators or padding. | ES2015 |
string.replace() |
Replace the first match of a string or regex (every match with the g flag) with new text or a function's result. | ES3 |
string.replaceAll() |
Replace every occurrence of a string (or regex with the g flag) with new text, without writing a regex. | ES2021 |
string.search() |
Return the index of the first regular-expression match, or -1 if there is none. | ES3 |
string.slice() |
Extract part of a string between two indexes; negative indexes count from the end. | ES3 |
string.split() |
Split a string into an array of substrings at each separator (a string or regex), with an optional limit. | ES3 |
string.startsWith() |
Return true if the string begins with the given text. Case-sensitive; an optional position starts the check later. | ES2015 |
string.substring() |
Return the part of a string between two indexes. Unlike slice(), negative values become 0 and swapped arguments are reordered. | ES1 |
string.toLowerCase() |
Return the string converted to lowercase. Use it for case-insensitive comparisons. | ES1 |
string.toLocaleLowerCase() |
Convert to lowercase using a language's rules, which matters for languages like Turkish. | ES3 |
string.toLocaleUpperCase() |
Convert to uppercase using a language's rules, for example Turkish or German special cases. | ES3 |
string.toUpperCase() |
Return the string converted to uppercase letters. Use toLocaleUpperCase() for language-specific rules. | ES1 |
string.toWellFormed() |
Return a copy where lone surrogates are replaced with U+FFFD, so the string can be encoded safely. | ES2024 |
string.trim() |
Remove whitespace (spaces, tabs, line breaks) from both ends of a string. | ES5 |
string.trimEnd() |
Remove whitespace (spaces, tabs, line breaks) from the end of a string only, leaving the start untouched. | ES2019 |
string.trimStart() |
Remove whitespace (spaces, tabs, line breaks) from the start of a string only, leaving the end untouched. | ES2019 |
String.fromCharCode() |
Create a string from UTF-16 code units, for example String.fromCharCode(72, 105) gives "Hi". | ES1 |
String.fromCodePoint() |
Create a string from Unicode code points, including emoji outside the BMP that fromCharCode() can't express in one number. | ES2015 |
String.raw() |
A template-literal tag that returns the raw string, with backslash sequences left as written. Handy for regexes and Windows paths. | ES2015 |