JavaScript Strings

The following tutorials cover String Operations in JavaScript.


Basics

  1. JavaScript – Create a string
    JavaScript Tutorial to define or initialize a string literal using different methods like enclosing the string in quotes, or String() constructor.
  2. JavaScript – Create empty string JavaScript Tutorial to create an empty string using single quotes, double quotes, ticks, or String() constructor.
  3. JavaScript – Compare strings JavaScript Tutorial to compare if two given strings are equal to each other, if first string greater than other, or if first string smaller than other.
  4. JavaScript – Compare strings ignoring case
  5. JavaScript – Count number of words in string JavaScript Tutorial to count the number of words in a given string, by splitting the string into words and then finding the length of that split array.
  6. JavaScript – Find string length JavaScript Tutorial to find the length of a string using string.length property.
  7. JavaScript – Iterate over characters of a string JavaScript Tutorial to iterate over each of the characters of the given string using a For loop.
  8. JavaScript – Multi-line strings JavaScript Tutorial to define a string that spans across multiple lines.
  9. JavaScript – Print string to console
  10. JavaScript – Substring of a string JavaScript Tutorial to find the part of the given string, based on start and end positions, using string.substring() method.

Checks

  1. JavaScript – Check if string is empty JavaScript Tutorial to check if given string is empty or not using Equal-to comparison operator.
  2. JavaScript – Check if strings are equal JavaScript Tutorial to check if two strings are equal using equal to comparison operator.
  3. JavaScript – Check if strings are equal ignoring case JavaScript Tutorial to check if two strings are equal, with the condition that we ignore the case of characters, using equal to comparison operator.
  4. JavaScript – Check if string contains specified substring JavaScript Tutorial to check if a string contains given substring using string.contains() method.
  5. JavaScript – Check if string contains specific character
  6. JavaScript – Check if string starts with specific string JavaScript Tutorial to check if a string starts with given prefix string using string.startsWith() method.
  7. JavaScript – Check if string ends with specific string JavaScript Tutorial to check if a string ends with given suffix string using string.endsWith() method.
  8. JavaScript – Check if string starts with http JavaScript Tutorial to check if given string starts with the string “http”. This is usually used to check if given string URL starts with http or not.
  9. JavaScript – Check if string starts with a number
  10. JavaScript – Check if string starts with an uppercase JavaScript Tutorial to check if the first character in the string is an uppercase character or not.
  11. JavaScript – Check if string starts with a lowercase
  12. JavaScript – Check if string ends with a punctuation
  13. JavaScript – Check if string ends with forward slash character
  14. JavaScript – Check if string contains a number
  15. JavaScript – Check if string contains only alphabets
  16. JavaScript – Check if string contains only numeric characters
  17. JavaScript – Check if string contains only lowercase
  18. JavaScript – Check if string contains only uppercase

Updates

  1. JavaScript – Append a string with suffix string
  2. JavaScript – Append a string with prefix string
  3. JavaScript – Concatenate strings JavaScript Tutorial to concatenate two or more strings using string.concat() method.
  4. JavaScript – Concatenate string and number
  5. JavaScript – Insert character at specific index
  6. JavaScript – Repeat string N times JavaScript Tutorial to create a string that is repeated N times from the given string.

Split Operations

  1. JavaScript – Split string JavaScript Tutorial to split a given string based on a delimiter string using String.split() method.
  2. JavaScript – Split string by a character
  3. JavaScript – Split string by comma
  4. JavaScript – Split string by single space
  5. JavaScript – Split string by new line
  6. JavaScript – Split string by any white space character
  7. JavaScript – Split string into substrings of specified length

Transformations

  1. JavaScript – Reverse a string JavaScript Tutorial to reverse a given string using String.split() , Array.reverse(), and Array.join() methods.
  2. JavaScript – String to lowercase JavaScript Tutorial to transform a given string to lowercase using String.toLowerCase() method.
  3. JavaScript – String to uppercase JavaScript Tutorial to transform a given string to uppercase using String.toUpperCase() method.
  4. JavaScript – Trim string JavaScript Tutorial to trim spaces around given string using String.trim() method.
  5. JavaScript – Join elements of string array with delimiter string
  6. JavaScript – Join elements of string array with comma

Delete Operations

  1. JavaScript – Remove first character of string JavaScript Tutorial to remove the first character of given string using slice() method.
  2. JavaScript – Remove last character of string JavaScript Tutorial to remove the last character of given string using slice() method.

Search

  1. JavaScript – Count number of occurrences of substring in a string
  2. JavaScript – Count number of overlapping occurrences of substring in a string
  3. JavaScript – Find the Index of substring in string JavaScript Tutorial to find the index of given substring in the string using string.indexOf() method.
  4. JavaScript – Find index of substring in a string
  5. JavaScript – Find index of last occurrence of substring in a string
  6. JavaScript – Find index of nth occurrence of substring in a string
  7. JavaScript – Find indexes of all occurrences of given substring in a string

Matchings

  1. JavaScript – Find all the matches of a Regular Expression in a string JavaScript Tutorial to find all the substrings in the given string that match the specified regular expression, using string.match() method.
  2. JavaScript – Check if string matches given regular expression
  3. JavaScript – Count number of substrings that match given regular expression
  4. JavaScript – Get all substrings that match given regular expression

Replacements

  1. JavaScript – Replace a substring in string JavaScript Tutorial to replace the first occurrence of specified substring in the string, with a replacement string.
  2. JavaScript – Replace all occurrences of a substring in string JavaScript Tutorial to replace all the occurrences of specified substring in the string, with a replacement string.
  3. JavaScript – Replace last occurrence of substring in string JavaScript Tutorial to replace the last occurrence of specified substring in the string, with a replacement string.
  4. JavaScript – Replace first substring that match with given regular expression
  5. JavaScript – Replace last substring that match with given regular expression
  6. JavaScript – Replace all substrings that match with given regular expression

Sorting

  1. JavaScript – Sort string array lexicographically JavaScript Tutorial to sort given string array based on the order they would come in a language dictionary.
  2. JavaScript – Sort strings in array based on length JavaScript Tutorial to sort given string array based on the length of the string elements in the array.

Filtering

  1. JavaScript – Filter string array based on string length JavaScript Tutorial to filter elements of string array based on length of the string elements.
  2. JavaScript – Remove empty strings from string array JavaScript Tutorial to remove empty string elements from array using String.trim() method, String.length property, and Array.filter() method.

Formating

  1. JavaScript – Format string JavaScript Tutorial to format a string.
  2. JavaScript – Variable inside a string

Conversions

  1. JavaScript – Convert string to integer JavaScript Tutorial to convert given string into integer, if the value inside string is a valid integer.
  2. JavaScript – Convert string to float JavaScript Tutorial to convert given string into floating point number, if the value inside string is a valid float.
  3. JavaScript – Convert number to string
  4. JavaScript – Convert boolean to string
  5. JavaScript – Convert string to boolean
  6. JavaScript – Convert array of characters to string JavaScript Tutorial to convert given array of characters into a string using Array.join() method.
  7. JavaScript – Convert string to array of characters JavaScript Tutorial to convert given string to an array of characters using String.split() method.
  8. JavaScript – Convert string to array of lines
  9. JavaScript – Convert Comma-Separated String into Array JavaScript Tutorial to convert given comma separated string into array, where the separated values are now elements in array.
  10. JavaScript – Convert array to CSV string

Exceptions

  1. JavaScript – Substring index out of bounds
  2. JavaScript – Get char at index – index out of bounds