JavaScript

String Methods

Master every essential JavaScript string method! A complete reference with brief explanations and live examples for case, search, extract, transform, and modern string operations.

By TechCoder TeamLast updated: 2026-06-02
In a Nutshell

Master every essential JavaScript string method! A complete reference with brief explanations and live examples for case, search, extract, transform, and modern string operations. This hands-on tutorial focuses on practical implementation of string methods concepts.

String Methods πŸ”§

JavaScript strings come with a rich set of built-in methods. This lesson is your complete reference β€” every method is explained briefly so you know exactly when to reach for it.

πŸ’‘ Remember: Strings are immutable β€” methods always return a new string.


1. Case Methods πŸ”‘

These methods change the letter casing of a string.

MethodWhat it does
toUpperCase()Converts every character to uppercase
toLowerCase()Converts every character to lowercase
toLocaleUpperCase(locale?)Uppercase using locale-specific rules (e.g. Turkish Δ°)
toLocaleLowerCase(locale?)Lowercase using locale-specific rules
JAVASCRIPT PLAYGROUND
⏳ Loading editor…

2. Whitespace Methods βœ‚οΈ

These methods remove extra spaces β€” very useful when cleaning user input from forms.

MethodWhat it does
trim()Removes whitespace from both ends
trimStart()Removes whitespace from the start only
trimEnd()Removes whitespace from the end only
JAVASCRIPT PLAYGROUND
⏳ Loading editor…

3. Search & Check Methods πŸ”

These methods let you check if something exists in a string, and where it is.

MethodWhat it does
includes(str, pos?)Returns true if string contains str
startsWith(str, pos?)Returns true if string starts with str
endsWith(str, len?)Returns true if string ends with str
indexOf(str, pos?)Returns index of first match, or -1
lastIndexOf(str, pos?)Returns index of last match, or -1
search(regex)Returns index of first regex match, or -1
match(regex)Returns array of matches (or null)
matchAll(regex)Returns iterator of all regex matches with capture groups
JAVASCRIPT PLAYGROUND
⏳ Loading editor…

4. Extraction Methods βœ‚οΈ

These methods extract a portion of a string without changing the original.

MethodWhat it does
slice(start, end?)Extracts from start to end (exclusive). Supports negative indices
substring(start, end?)Like slice but ignores negative indices
at(index)Returns character at index. Supports negative index (counts from end)
charAt(index)Returns character at index (empty string if out of range)
charCodeAt(index)Returns UTF-16 code of character at index
String.fromCharCode(...codes)Creates a string from char codes
JAVASCRIPT PLAYGROUND
⏳ Loading editor…

5. Transform Methods πŸ”„

These methods create modified copies of a string β€” the original is never changed.

MethodWhat it does
replace(target, replacement)Replaces the first occurrence
replaceAll(target, replacement)Replaces all occurrences
split(separator, limit?)Splits string into an array by separator
repeat(count)Returns the string repeated count times
padStart(length, pad?)Pads the start until length is reached
padEnd(length, pad?)Pads the end until length is reached
concat(...strings)Joins strings together (prefer template literals instead)
JAVASCRIPT PLAYGROUND
⏳ Loading editor…

6. Utility Methods πŸ§ͺ

A few extra methods useful in specific situations.

MethodWhat it does
lengthProperty β€” total number of characters in the string
localeCompare(str)Compares strings in locale-aware order (returns -1, 0, or 1)
normalize(form?)Normalises Unicode to a standard form (NFC, NFD, etc.)
codePointAt(index)Like charCodeAt but handles full Unicode code points
JAVASCRIPT PLAYGROUND
⏳ Loading editor…

Practical Example: Name Formatter πŸ‘€

JAVASCRIPT PLAYGROUND
⏳ Loading editor…

AI Mentor

Confused about "JavaScript string methods: case, whitespace, search, extract, transform and utility"? Ask our AI mentor for a simplified explanation.

Quiz

Quiz

Question 1 of 5

Which method removes whitespace only from the beginning of a string?

trim()
trimStart()
trimEnd()
strip()

Key Takeaways

βœ… Case: toUpperCase, toLowerCase β€” normalise and compare strings.
βœ… Whitespace: trim, trimStart, trimEnd β€” clean up user input.
βœ… Search: includes, startsWith, endsWith, indexOf, matchAll β€” find what you need.
βœ… Extract: slice, at, charAt β€” get substrings with ease.
βœ… Transform: replace, replaceAll, split, padStart, repeat β€” reshape strings.

What's Next?

Now that you're fluent with strings, let's make your code smart with Conditionals!

Keep coding! πŸš€