JavaScript_String_Methods_Styled
JavaScript_String_Methods_Styled
charAt()
Description: Returns the character at a specified index.
Example:
console.log(str.charAt(6)); // Output: W
charCodeAt()
Description: Returns the Unicode of the character at a specified index.
Example:
console.log(str.charCodeAt(6)); // Output: 87
concat()
Description: Joins two or more strings.
Example:
includes()
Description: Checks if a string contains a specified value.
Example:
endsWith()
Description: Checks if a string ends with a specified value.
Example:
let str = "Hello World";
indexOf()
Description: Returns the position of the first occurrence of a specified value.
Example:
console.log(str.indexOf("World")); // Output: 6
lastIndexOf()
Description: Returns the position of the last occurrence of a specified value.
Example:
console.log(str.lastIndexOf("Hello")); // Output: 13
localeCompare()
Description: Compares two strings in the current locale.
Example:
match()
Description: Matches a string against a regular expression.
Example:
matchAll()
Description: Returns all matches of a string against a regular expression.
Example:
let str = "test1 test2 test3";
["test3"]]
padStart()
Description: Pads the string with a specified character at the start.
Example:
padEnd()
Description: Pads the string with a specified character at the end.
Example:
repeat()
Description: Repeats a string a specified number of times.
Example:
replace()
Description: Replaces a specified value with another value.
Example:
replaceAll()
Description: Replaces all occurrences of a specified value.
Example:
slice()
Description: Extracts a part of a string and returns it as a new string.
Example:
split()
Description: Splits a string into an array of substrings.
Example:
startsWith()
Description: Checks if a string starts with a specified value.
Example:
substring()
Description: Extracts characters between two indices.
Example:
toLowerCase()
Description: Converts a string to lowercase.
Example:
let str = "Hello World";
toUpperCase()
Description: Converts a string to uppercase.
Example:
trim()
Description: Removes whitespace from both ends of a string.
Example:
trimStart()
Description: Removes whitespace from the beginning of a string.
Example:
trimEnd()
Description: Removes whitespace from the end of a string.
Example:
valueOf()
Description: Returns the primitive value of a string.
Example: