JavaScript String Methods

About This Index
This page is the JavaScript String Methods index for the tutorial track. Each row links to a full guide with syntax, examples, and FAQs.
Learn what a String is on /js/string. Use this page when you need a specific API such as slice(), includes(), or trim().
Start with slice(), includes(), trim(), and replace()—then browse the rest by category. HTML wrapper methods such as bold() are legacy; prefer document.createElement() in new code.
How to Call a String Method
Instance methods use a dot; a few helpers use String:
const title = " JavaScript ";
// Instance (String.prototype)
title.trim(); // "JavaScript"
title.includes("Java"); // true
"Hello".slice(0, 2); // "He"
"a-b-c".split("-"); // ["a", "b", "c"]
// Static (on String)
String.fromCharCode(65); // "A"
String.fromCodePoint(128512); // "😀" JavaScript String Methods Table
All method guides in this JavaScript tutorial series (49 tutorials).
HTML Wrapper Methods (Deprecated)
13 methodsLegacy helpers that build HTML strings. Prefer document.createElement() in new code.
| Method | Description | Tutorial |
|---|---|---|
anchor() | Deprecated HTML wrapper: returns a string with <a name="..."> markup — prefer document.createElement(). | Open |
big() | Deprecated HTML wrapper: returns a string with <big> markup — prefer CSS font-size. | Open |
blink() | Deprecated HTML wrapper: returns a string with <blink> markup — avoid blinking text. | Open |
bold() | Deprecated HTML wrapper: returns a string with <b> markup — prefer createElement or CSS font-weight. | Open |
fixed() | Deprecated HTML wrapper: returns a string with <tt> markup — prefer CSS font-family: monospace. | Open |
fontcolor() | Deprecated HTML wrapper: returns a string with <font color="..."> markup — prefer CSS color. | Open |
fontsize() | Deprecated HTML wrapper: returns a string with <font size="..."> markup — prefer CSS font-size. | Open |
italics() | Deprecated HTML wrapper: returns a string with <i> markup — prefer createElement or CSS font-style. | Open |
link() | Deprecated HTML wrapper: returns a string with <a href="..."> markup — prefer document.createElement("a"). | Open |
small() | Deprecated HTML wrapper: returns a string with <small> markup — prefer createElement("small") or CSS font-size. | Open |
strike() | Deprecated HTML wrapper: returns a string with <strike> markup — prefer createElement("s") or createElement("del"). | Open |
sub() | Deprecated HTML wrapper: returns a string with <sub> markup — prefer document.createElement("sub"). | Open |
sup() | Deprecated HTML wrapper: returns a string with <sup> markup — prefer document.createElement("sup"). | Open |
Character Access
5 methodsRead characters, code units, code points, or iterate the string.
| Method | Description | Tutorial |
|---|---|---|
at() | Return the UTF-16 code unit at an index — supports negative offsets from the end (at(-1) is last). | Open |
charAt() | Return the UTF-16 code unit at a zero-based index — out of range returns "" (no negative indexes). | Open |
charCodeAt() | Return the UTF-16 code unit at an index as a number (0–65535) — out of range returns NaN. | Open |
codePointAt() | Return the full Unicode code point at a UTF-16 index — out of range returns undefined (handles emoji). | Open |
[Symbol.iterator]() | Make strings iterable by Unicode code points — powers for...of and spread; surrogate pairs stay together. | Open |
Search & Test
7 methodsFind substrings and test prefixes or suffixes.
| Method | Description | Tutorial |
|---|---|---|
includes() | Case-sensitive substring search that returns true or false — optional start position; regex not allowed. | Open |
indexOf() | Return the first index of a substring, or -1 if missing — optional start position; case-sensitive. | Open |
lastIndexOf() | Return the last index of a substring, or -1 if missing — optional from-position; case-sensitive. | Open |
startsWith() | Case-sensitive prefix check that returns true or false — optional position; regex throws TypeError. | Open |
search() | Return the index of the first regex match, or -1 — g flag has no effect; strings are coerced to RegExp. | Open |
match() | Match a string against a regular expression — returns an Array or null; g flag changes the result shape. | Open |
matchAll() | Iterate all regex matches with capturing groups — requires the g flag; returns an iterator. | Open |
Unicode & Well-Formed
3 methodsNormalize Unicode forms and detect or repair lone UTF-16 surrogates.
| Method | Description | Tutorial |
|---|---|---|
isWellFormed() | Return true if the string has no lone UTF-16 surrogates — useful before encodeURI(); pair with toWellFormed(). | Open |
toWellFormed() | Replace lone UTF-16 surrogates with U+FFFD (�) — safe for encodeURI(); pair with isWellFormed(). | Open |
normalize() | Return a Unicode Normalization Form (NFC/NFD/NFKC/NFKD) — default NFC; use before comparing lookalike text. | Open |
Extract & Split
4 methodsPull out parts of a string or split into arrays.
| Method | Description | Tutorial |
|---|---|---|
slice() | Extract a section into a new string — exclusive end index; negatives count from the end. | Open |
substring() | Extract between two indexes (exclusive end) — swaps if start > end; negatives treated as 0. | Open |
substr() | Legacy start+length extractor (deprecated Annex B) — prefer slice(); negative length returns "". | Open |
split() | Divide a string into an array by a string or regex separator — optional limit; capturing groups appear in the result. | Open |
Transform & Pad
9 methodsChange case, trim whitespace, pad, or repeat text.
| Method | Description | Tutorial |
|---|---|---|
toLowerCase() | Convert to lowercase with Unicode default mappings — great for case-insensitive compares; no locales arg. | Open |
toLocaleLowerCase() | Locale-aware lowercase — optional BCP 47 locales; Turkish İ differs from toLowerCase(). | Open |
toLocaleUpperCase() | Locale-aware uppercase — optional BCP 47 locales; Turkish i → İ; length may grow (ß → SS). | Open |
trim() | Remove whitespace from both ends — spaces, tabs, newlines; middle spaces kept; pair with trimStart/trimEnd. | Open |
trimStart() | Remove leading whitespace only — keeps trailing spaces; alias trimLeft(); pair with trim/trimEnd. | Open |
trimEnd() | Remove trailing whitespace only — keeps leading spaces; alias trimRight(); pair with trim/trimStart. | Open |
padStart() | Pad the start of a string to a target length — default space filler; great for zero-padding and masks. | Open |
padEnd() | Pad the end of a string to a target length — default space filler; padString repeats or truncates. | Open |
repeat() | Build a new string by concatenating the original count times — RangeError for negative or Infinity. | Open |
Combine & Replace
2 methodsJoin strings or swap matched text for new content.
| Method | Description | Tutorial |
|---|---|---|
replace() | Replace the first string match or regex matches — use g for all; support $ groups and replacer functions. | Open |
replaceAll() | Replace every string or global-regex match — TypeError if a RegExp is missing the g flag. | Open |
Compare & Convert
3 methodsSort-friendly comparison and primitive conversion.
| Method | Description | Tutorial |
|---|---|---|
localeCompare() | Locale-aware string ordering — returns <0 / 0 / >0; optional locales and options (sensitivity, numeric). | Open |
toString() | Return the string primitive — unwraps new String(...); same as valueOf(); TypeError for non-string this. | Open |
valueOf() | Return the string primitive — same as toString(); unwraps new String(...); usually called by the engine. | Open |
Static Methods
3 methodsHelpers on the String constructor — not called on an instance.
| Method | Description | Tutorial |
|---|---|---|
fromCharCode() | Static helper: build a string from UTF-16 code units (0–65535) — pair with charCodeAt(); prefer fromCodePoint() for emoji. | Open |
fromCodePoint() | Static helper: build a string from full Unicode code points (0–0x10FFFF) — emoji in one arg; invalid values throw RangeError. | Open |
raw() | Static template tag: keep escape sequences raw while still evaluating ${} — great for paths and RegExp sources. | Open |
Frequently Asked Questions
Start with slice()
Open the extraction guide—syntax, examples, and FAQs.
10 people found this page helpful
