JavaScript provides a rich library of built-in methods on strings to search, extract, replace, format, and split text. Because strings are immutable, all string methods return a new string without modifying the original.
.includes() (ES6)Checks if a substring exists; returns true or false (case-sensitive):
.startsWith() and .endsWith() (ES6).indexOf() and .lastIndexOf()Returns the starting index of substring, or -1 if not found:
.slice()The .slice(startIndex, endIndex) method extracts a portion of a string:
startIndex: Index where extraction begins (inclusive).endIndex (optional): Index where extraction ends (exclusive)..replace() and .replaceAll().split().split(delimiter) splits a string into an array of substrings based on a separator:
str.trim() do?"Frontend".slice(0, 5)?str = "apple,banana,orange", what does str.split(",") return?"coding".includes("od") evaluate to?"hello".indexOf("z")?Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| String Basics | Template Literals (Basics) |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.