JavaScript String Methods

Created with Sketch.

JavaScript String Methods

This page provides string methods that help you manipulate strings effectively.

Section 1. Searching

  • 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

  • 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

  • padStart() & padEnd() – pad a string with another string until the result string reaches the given length.

Section 4. Extracting

  • 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

  • concat() – concatenate multiple strings into a new string.
  • Template literals – learn how to substitute variables in a string.

Section 6. Replacing

  • 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

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

Leave a Reply

Your email address will not be published.