JavaScript logoJavaScript INTERMEDIATE

JavaScript String Methods

Complete guide to JavaScript string methods and text manipulation

5 min read
javascriptstringsmethodstext

Case Manipulation

Transform string case for formatting and comparison

Changing Case

Convert strings to uppercase, lowercase, or capitalize for consistent formatting

javascript

Searching & Testing

Find and test for substrings and patterns within strings

Finding Substrings

Search for text within strings using indexOf, includes, and search methods

javascript

Accessing Characters

Access individual characters and their codes using charAt, charCodeAt, and bracket notation

javascript

Start & End Checking

Check if strings start or end with specific substrings

javascript
💡 More readable than indexOf() === 0 or slice() checks
⚡ Second parameter specifies search position
📌 Case-sensitive by default - lowercase for case-insensitive
✅ Perfect for validation and conditional logic

Extracting Substrings

Extract portions of strings using various methods

Substring Methods

Extract portions of strings using slice, substring, and substr methods

javascript

Modern Character Access

Access characters using the modern at() method with negative indexing

javascript
💡 at() is the modern way to access characters
⚡ Negative indices work without length calculation
📌 Returns undefined for out-of-bounds (like bracket notation)
✅ Cleaner than str[str.length - 1] for end access

String Modification

Modify strings through replacement, trimming, and splitting

Replacing Text

Replace text patterns using replace and replaceAll with strings or regex

javascript

Trimming & Padding

Remove whitespace with trim methods or add padding to reach desired length

javascript

Splitting & Joining

Convert between strings and arrays using split and join methods

javascript

String Formatting

Format strings with repetition, padding, and localization

Repeat & Concatenation

Repeat strings multiple times or combine them using various methods

javascript

Normalization & Locale

Handle Unicode normalization and locale-specific string operations

javascript

Template Literals & String.raw

Use template literals for string interpolation and String.raw for raw strings

javascript
💡 Template literals are the modern way to build strings
⚡ String.raw preserves escape sequences literally
📌 Tagged templates enable DSLs and string processing
✅ Use String.raw for Windows paths and regex patterns

Regular Expressions

Use regex patterns for advanced string operations

Regex String Methods

Use regular expressions with match, matchAll, and search for pattern matching

javascript