JavaScript Strings Practice Exercises
Text manipulation, methods, and formatting
Challenges
String Positions
String Positions
Strings are ordered. The first character is at index `0`, and the last character...
String Length
`length` tells you how many characters a string contains. Spaces count because t...
Bracket Access
Bracket notation reads one character at a known position. It is useful when a st...
Lowercase Text
Programs often normalize labels before comparing or storing them. A lowercase co...
Trim Whitespace
`trim` removes whitespace from the start and end of a string. It does not remove...
Repeat Text
`repeat` creates a new string by repeating another string a chosen number of tim...
Search Inside Text
`includes` answers a yes-or-no question: does this string contain that text? Yo...
Slice From the End
`slice` can read from the end of a string with a negative start index. That is u...
Normalize Input
User-entered text often has accidental spaces and inconsistent casing. A reusabl...
Check the End
For email domains, the position of the match matters. `person@example.com` shoul...
Split a Name
When text has a reliable separator, you can split it into pieces and read the ch...
URL Slugs
A slug is a readable piece of a URL. It usually has lowercase words separated by...
Debug a Slice
`slice(start, end)` includes the start index but stops before the end index. Off...
Pick the Right Search
Two search functions can both return true for the same text while answering diff...
Pad Text
`padStart` adds characters to the front of a string until it reaches a target le...
Replace Repeated Text
When the same sensitive word can appear more than once, replacing only the first...
Extract Between Markers
Practice JavaScript string slicing by extracting text only when start and end ma...
Mask Personal Text
Mask email text with JavaScript string methods by normalizing the address and hi...
Count Repeated Text
Count JavaScript string matches by finding non-overlapping term occurrences whil...
Valid Anagram
Two words are anagrams when they use the same characters the same number of time...
Truncate Carefully
Practice JavaScript string truncation by building a summary helper that respects...
Parse a Tag List
Turn comma-separated JavaScript string input into a clean array of labels. This ...
String Methods Return New Values
Debug a JavaScript string cleanup bug where calling trim is not enough unless th...
Index Results Are Numbers
Fix a JavaScript string search bug where indexOf position numbers are treated li...
Split on the Last Marker
Practice JavaScript string indexing by splitting a filename on its final dot ins...
Render Placeholder Text
Practice JavaScript string replacement by rendering placeholder text from an obj...
Parse Query Strings
Convert URL query text with JavaScript string parsing into an object of decoded ...
Parse Quoted CSV
Walk a CSV line with JavaScript string parsing while tracking whether the curren...
Highlight Search Matches
Practice JavaScript string searching by highlighting every case-insensitive matc...