JavaScript Strings
The following tutorials cover String Operations in JavaScript.
Basics
- 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.
- JavaScript – Create empty string JavaScript Tutorial to create an empty string using single quotes, double quotes, ticks, or String() constructor.
- 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.
- JavaScript – Compare strings ignoring case
- 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.
- JavaScript – Find string length JavaScript Tutorial to find the length of a string using
string.length
property. - JavaScript – Iterate over characters of a string JavaScript Tutorial to iterate over each of the characters of the given string using a For loop.
- JavaScript – Multi-line strings JavaScript Tutorial to define a string that spans across multiple lines.
- JavaScript – Print string to console
- 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
- JavaScript – Check if string is empty JavaScript Tutorial to check if given string is empty or not using Equal-to comparison operator.
- JavaScript – Check if strings are equal JavaScript Tutorial to check if two strings are equal using equal to comparison operator.
- 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.
- JavaScript – Check if string contains specified substring JavaScript Tutorial to check if a string contains given substring using
string.contains()
method. - JavaScript – Check if string contains specific character
- JavaScript – Check if string starts with specific string JavaScript Tutorial to check if a string starts with given prefix string using
string.startsWith()
method. - JavaScript – Check if string ends with specific string JavaScript Tutorial to check if a string ends with given suffix string using string.endsWith() method.
- 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.
- JavaScript – Check if string starts with a number
- 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.
- JavaScript – Check if string starts with a lowercase
- JavaScript – Check if string ends with a punctuation
- JavaScript – Check if string ends with forward slash character
- JavaScript – Check if string contains a number
- JavaScript – Check if string contains only alphabets
- JavaScript – Check if string contains only numeric characters
- JavaScript – Check if string contains only lowercase
- JavaScript – Check if string contains only uppercase
Updates
- JavaScript – Append a string with suffix string
- JavaScript – Append a string with prefix string
- JavaScript – Concatenate strings JavaScript Tutorial to concatenate two or more strings using
string.concat()
method. - JavaScript – Concatenate string and number
- JavaScript – Insert character at specific index
- JavaScript – Repeat string N times JavaScript Tutorial to create a string that is repeated N times from the given string.
Split Operations
- JavaScript – Split string JavaScript Tutorial to split a given string based on a delimiter string using
String.split()
method. - JavaScript – Split string by a character
- JavaScript – Split string by comma
- JavaScript – Split string by single space
- JavaScript – Split string by new line
- JavaScript – Split string by any white space character
- JavaScript – Split string into substrings of specified length
Transformations
- JavaScript – Reverse a string JavaScript Tutorial to reverse a given string using
String.split()
,Array.reverse()
, andArray.join()
methods. - JavaScript – String to lowercase JavaScript Tutorial to transform a given string to lowercase using
String.toLowerCase()
method. - JavaScript – String to uppercase JavaScript Tutorial to transform a given string to uppercase using
String.toUpperCase()
method. - JavaScript – Trim string JavaScript Tutorial to trim spaces around given string using
String.trim()
method. - JavaScript – Join elements of string array with delimiter string
- JavaScript – Join elements of string array with comma
Delete Operations
- JavaScript – Remove first character of string JavaScript Tutorial to remove the first character of given string using
slice()
method. - JavaScript – Remove last character of string JavaScript Tutorial to remove the last character of given string using
slice()
method.
Search
- JavaScript – Count number of occurrences of substring in a string
- JavaScript – Count number of overlapping occurrences of substring in a string
- JavaScript – Find the Index of substring in string JavaScript Tutorial to find the index of given substring in the string using string.indexOf() method.
- JavaScript – Find index of substring in a string
- JavaScript – Find index of last occurrence of substring in a string
- JavaScript – Find index of nth occurrence of substring in a string
- JavaScript – Find indexes of all occurrences of given substring in a string
Matchings
- 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.
- JavaScript – Check if string matches given regular expression
- JavaScript – Count number of substrings that match given regular expression
- JavaScript – Get all substrings that match given regular expression
Replacements
- JavaScript – Replace a substring in string JavaScript Tutorial to replace the first occurrence of specified substring in the string, with a replacement string.
- 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.
- 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.
- JavaScript – Replace first substring that match with given regular expression
- JavaScript – Replace last substring that match with given regular expression
- JavaScript – Replace all substrings that match with given regular expression
Sorting
- JavaScript – Sort string array lexicographically JavaScript Tutorial to sort given string array based on the order they would come in a language dictionary.
- 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
- JavaScript – Filter string array based on string length JavaScript Tutorial to filter elements of string array based on length of the string elements.
- 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
- JavaScript – Format string JavaScript Tutorial to format a string.
- JavaScript – Variable inside a string
Conversions
- JavaScript – Convert string to integer JavaScript Tutorial to convert given string into integer, if the value inside string is a valid integer.
- JavaScript – Convert string to float JavaScript Tutorial to convert given string into floating point number, if the value inside string is a valid float.
- JavaScript – Convert number to string
- JavaScript – Convert boolean to string
- JavaScript – Convert string to boolean
- JavaScript – Convert array of characters to string JavaScript Tutorial to convert given array of characters into a string using
Array.join()
method. - JavaScript – Convert string to array of characters JavaScript Tutorial to convert given string to an array of characters using
String.split()
method. - JavaScript – Convert string to array of lines
- 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.
- JavaScript – Convert array to CSV string
Exceptions
- JavaScript – Substring index out of bounds
- JavaScript – Get char at index – index out of bounds