Most Usages of String Methods in JavaScript
A practical walkthrough of frequently used JavaScript string methods with examples for search, extraction, replacement, and formatting.
Fast string utility pattern
const text = 'I love Bangladesh. Bangladesh is beautiful';
const methods = {
first: text.indexOf('Bangladesh'),
last: text.lastIndexOf('Bangladesh'),
replaced: text.replace(/Bangladesh/g, 'BD'),
words: text.split(' ')
};
Core methods usually combine into compact utility helpers.
Original publication
This post is adapted from the original Medium article: Most Usages of String methods in JavaScript
Why this topic matters
String processing appears everywhere: parsing user input, formatting messages, matching keywords, and shaping API output. Knowing a small set of reliable methods removes a lot of day-to-day friction.
Frequently used methods
lengthfor size checks and validation.indexOfandlastIndexOffor position lookup.charAtor bracket indexing for targeted access.replacefor controlled substitutions.slicefor extracting segments.splitfor tokenizing into arrays.includesfor boolean containment checks.substrandconcatfor legacy-compatible workflows.
Practical guidance
- Prefer
includeswhen you only need true/false checks. - Use regex with
replacewhen multiple matches are expected. - Keep edge cases in mind for negative indexes and empty delimiters.
- Treat string operations as immutable transforms and return new values.
Read more
For full examples and the original explanations, read the source article:
Read the full article on Medium
Related posts
10 Important ES6 Features in JavaScript That Make Life Easier
A concise guide to the ES6 features that most improve readability, maintainability, and day-to-day developer productivity.
Basic 10 JavaScript Problem-Solving Exercises Developers Should Practice
Ten foundational JavaScript practice patterns for arrays, strings, loops, recursion, and number logic.
Top 10 Important Things in React Every Developer Should Know
A practical recap of foundational React concepts including lifecycle, hooks, composition patterns, and rendering decisions.