- String Length
- Case Conversion
- Substring Extraction
- String Manipulation
- String Formatting
- Template Literal (ES6)
str.length
: Returns the length of the string.
-
str.toUpperCase()
: Converts the string to uppercase.- Parameters: None.
- Example:
const str = 'hello'; console.log(str.toUpperCase()); // Output: HELLO
-
str.toLowerCase()
: Converts the string to lowercase.- Parameters: None.
- Example:
const str = 'WORLD'; console.log(str.toLowerCase()); // Output: world
-
str.slice(startIndex, endIndex)
: Extracts a portion of the string fromstartIndex
toendIndex
(exclusive).- Parameters:
startIndex
: The starting index of the substring (inclusive).endIndex
(optional): The ending index of the substring (exclusive).
- Example:
const str = 'Hello, World!'; console.log(str.slice(7, 12)); // Output: World
- Parameters:
-
str.substring(startIndex, endIndex)
: Extracts a portion of the string fromstartIndex
toendIndex
(exclusive), but treats negative indices as 0.- Parameters:
startIndex
: The starting index of the substring (inclusive).endIndex
(optional): The ending index of the substring (exclusive).
- Example:
const str = 'Hello, World!'; console.log(str.substring(7, 12)); // Output: World
- Parameters:
-
str.substr(startIndex, length)
: Extracts a portion of the string starting fromstartIndex
with the specifiedlength
.- Parameters:
startIndex
: The starting index of the substring (inclusive).length
(optional): The length of the substring.
- Example:
const str = 'Hello, World!'; console.log(str.substr(7, 5)); // Output: World
- Parameters:
-
str.concat(str2, str3, ..., strN)
: Concatenates one or more strings with the original string.- Parameters:
str2, str3, ..., strN
(optional): Strings to concatenate.
- Example:
const str1 = 'Hello'; const str2 = 'World'; console.log(str1.concat(', ', str2)); // Output: Hello, World
- Parameters:
-
str.replace(searchValue, replaceValue)
: Replaces occurrences ofsearchValue
withreplaceValue
.- Parameters:
searchValue
: The value to search for.replaceValue
: The value to replace occurrences ofsearchValue
.
- Example:
const str = 'Hello, World!'; console.log(str.replace('World', 'John')); // Output: Hello, John!
- Parameters:
-
str.trim()
: Removes leading and trailing whitespace from the string.- Parameters: None.
- Example:
const str = ' Hello, World! '; console.log(str.trim()); // Output: Hello, World!
-
str.split(separator)
: Splits the string into an array of substrings based on theseparator
character.- Parameters:
separator
: The character or substring used to determine where to split the string.
- Example:
const str = 'Hello,World,!'; console.log(str.split(',')); // Output: ['Hello', 'World', '!']
- Parameters:
-
str.charAt(index)
: Returns the character at the specifiedindex
.- Parameters:
index
: The index of the character to retrieve.
- Example:
const str = 'Hello, World!'; console.log(str.charAt(7)); // Output: W
- Parameters:
-
str.charCodeAt(index)
: Returns the Unicode value of the character at the specifiedindex
.- Parameters:
index
: The index of the character.
- Example:
const str = 'Hello, World!'; console.log(str.charCodeAt(7)); // Output: 87
- Parameters:
-
str.indexOf(searchValue, startIndex)
: Returns the index of the first occurrence ofsearchValue
starting fromstartIndex
.- Parameters:
searchValue
: The value to search for.startIndex
(optional): The index to start searching from.
- Example:
const str = 'Hello, World!'; console.log(str.indexOf('o')); // Output: 4
- Parameters:
-
str.lastIndexOf(searchValue, startIndex)
: Returns the index of the last occurrence ofsearchValue
starting fromstartIndex
.- Parameters:
searchValue
: The value to search for.startIndex
(optional): The index to start searching from.
- Example:
const str = 'Hello, World!'; console.log(str.lastIndexOf('o')); // Output: 8
- Parameters:
-
str.startsWith(searchValue)
: Checks if the string starts withsearchValue
.- Parameters:
searchValue
: The value to search for.
- Example:
const str = 'Hello, World!'; console.log(str.startsWith('Hello')); // Output: true
- Parameters:
-
str.endsWith(searchValue)
: Checks if the string ends withsearchValue
.- Parameters:
searchValue
: The value to search for.
- Example:
const str = 'Hello, World!'; console.log(str.endsWith('World!')); // Output: true
- Parameters:
-
str.includes(searchValue)
: Checks if the string containssearchValue
.- Parameters:
searchValue
: The value to search for.
- Example:
const str = 'Hello, World!'; console.log(str.includes('World')); // Output: true
- Parameters:
-
str.padStart(targetLength, padString)
: Pads the string from the start withpadString
until it reaches thetargetLength
.- Parameters:
targetLength
: The length the string should reach.padString
(optional): The string to pad with (default is a space).
- Example:
const str = 'Hello'; console.log(str.padStart(10, 'X')); // Output: XXXXHello
- Parameters:
-
str.padEnd(targetLength, padString)
: Pads the string from the end withpadString
until it reaches thetargetLength
.- Parameters:
targetLength
: The length the string should reach.padString
(optional): The string to pad with (default is a space).
- Example:
const str = 'Hello'; console.log(str.padEnd(10, 'X')); // Output: HelloXXXX
- Parameters:
-
str.repeat(count)
: Repeats the stringcount
number of times.- Parameters:
count
: The number of times to repeat the string.
- Example:
const str = 'Hello'; console.log(str.repeat(3)); // Output: HelloHelloHello
- Parameters:
${variable}
: Interpolates the value ofvariable
within a string.- Multiline strings: Enclose multiline strings using backticks (`).
For more detailed information and additional string methods, please refer to the documentation of the programming language or framework you are using.