The length method is used to check the length of the string
const str = "Hello"; console.log(str.length); //output will be 5
charAt()Returns the character at the specified index.
charCodeAt() Returns the Unicode value of the character at the specified index.
const str = "Hello"; console.log(str.charAt(0)); const str = "Hello"; console.log(str.charCodeAt(0));
Returns the Unicode code point of the character at the specified index.
const str = "Hello"; console.log(str.codePointAt(0)); // 72 (Unicode code point of "H")
Concatenates two or more strings.
Returns the character at the specified index, similar to charAt(). Supports negative indices.
const str1 = "Hello"; const str2 = " World"; console.log(str1.concat(str2)); const str = "Hello"; console.log(str.at(0)); // "H"
Returns the character at the specified index, similar to charAt(). String[] not used for negative indexes.
cconst str = "Hello"; console.log(str[0]); // "H"
slice() extracts a part of a string and returns the extracted part in a new string.
substring() is similar to slice().
The difference is that start and end values less than 0 are treated as 0 in substring().
const str = "Hello World"; console.log(str.slice(6)); // "World" console.log(str.slice(0, 5)); // "Hello" const str = "Hello World"; console.log(str.substring(2, 6));
toUpperCase() Converts the string to uppercase.
toLowerCase() Converts the string to lowercase.
const str = "hello"; console.log(str.toUpperCase()); const str = "HELLO"; console.log(str.toLowerCase());
isWellFormed() This method checks if a string is well-formed according to specific rules.
This method takes a string and returns a well-formed version of it. It may replace or remove characters that are not well-formed according to specific rules.
const str = "Hello"; console.log(str.isWellFormed()); const str = "\uD800"; // lone surrogate console.log(str.toWellFormed()); // "\uFFFD" (replacement character)
trim() Removes whitespace from both ends.
trimStart() Removes whitespace from the start.
trimEnd() Removes whitespace from the end.
const str = " Hello "; console.log(str.trim()); // "Hello" const str = " Hello "; console.log(str.trimStart()); // "Hello " const str = " Hello "; console.log(str.trimEnd()); /
padStart() Pads the string with a specified string from the start.
padEnd() Pads the string with a specified string from the end.
const str = "Hello"; console.log(str.padStart(8, "*")); // "***Hello" const str = "Hello"; console.log(str.padEnd(8, "*")); // "Hello***"
repeat() Repeats the string much time you want.
The replace() method replaces a specified value with another value in a string:
const str = "Hello"; console.log(str.repeat(3)); let text = "Please visit"; let newText=text.replace("visit", "he")
replaceAll() are used to replace all of the things that were selected
split() method is used to split a string into an array based on a given separator (like space, comma, or any character).
const str = "Hello World, Hello!"; console.log(str.replaceAll("Hello", "Hi")); // "Hi World, Hi!" const str = "Hello,World,!"; console.log(str.split(",,,")); // ["Hello",,, "World",,, "!"]