JavaScript String Methods

Valento
Make your net worth less undefined.
Track your accounts, assets, and debts in one simple financial dashboard.
Explore Valento 

This page provides the most commonly used JavaScript string methods that help you manipulate strings effectively.

Section 1. Searching #

Mastering the string search methods can help you analyze text more efficiently. These sections introduce the string search methods that allow you to locate and verify substrings within strings.

  • search() – locate a substring in a string using a regular expression.
  • indexOf() – get the index of the first occurrence of a substring in a string.
  • lastIndexOf() – find the index of the last occurrence of a substring in a string.
  • includes() – check if a string contains a substring.
  • startsWith() – check if a string starts with another string.
  • endsWith() – determine if a string ends with another string.

Section 2. Trimming #

This section introduces the string trimming methods that allow you to remove unwanted whitespace characters from a string, ensuring your text is clean and well-formatted.

  • trim() – remove whitespace characters from a string.
  • trimStart() – remove the leading whitespace characters of a string.
  • trimEnd() – remove the ending whitespace characters of a string.

Section 3. Padding #

Padding strings is a useful technique for formatting text. This section introduces two string methods padStart() and padEnd() for padding strings.

  • padStart() – pad the beginning of a string with another string until the resulting string reaches a specified length.
  • padEnd() – pad the end of a string with another string until the resulting string reaches a certain length.

Section 4. Extracting #

This section introduces the extracting string methods that allow you to break down strings into smaller pieces and extract specific substrings:

  • split() – split a string into an array of substrings.
  • substring() – extract a substring from a string.
  • slice() – extract a part of a string.

Section 5. Concatenating & interpolating #

Learn how to concatenate strings and substitute variables directly within strings using template literals.

  • concat() – concatenate multiple strings into a new string.
  • Template literals – learn how to use template literal to substitute variables directly within a string in a more flexible and readable way.

Section 6. Replacing #

This section introduces replacing string methods that allow you to perform data cleaning and transformation effectively.

  • replace() – replace a substring in a string with a new one.
  • replaceAll() – replace all occurrences of a substring that matches a pattern with a new one.

Section 7. Changing cases #

This section introduces various case-changing methods that allow you to convert characters in strings to lowercase or uppercase.

  • toUpperCase – return a string with all characters converted to uppercase.
  • toLowerCase – return a string with all characters converted to lowercase.

Was this helpful?