1. length
Property
The length
property returns the length of a string.
let str = "Hello, world!";
let length = str.length;
console.log(length); // Output: 13
2. toUpperCase()
Method
The toUpperCase()
method converts a string to uppercase letters.
let str = "hello";
let upperStr = str.toUpperCase();
console.log(upperStr); // Output: "HELLO"
3. includes()
Method
The includes()
method checks if a string contains a specified substring.
let str = "Hello, world!";
let hasHello = str.includes("Hello");
console.log(hasHello); // Output: true
4. slice()
Method
The slice()
method extracts a part of a string and returns a new string.
let str = "Hello, world!";
let slicedStr = str.slice(0, 5);
console.log(slicedStr); // Output: "Hello"
5. replace()
Method
The replace()
method replaces a specified value with another value in a string.
let str = "Hello, world!";
let newStr = str.replace("world", "JavaScript");
console.log(newStr); // Output: "Hello, JavaScript!"
6. charAt()
Method
The charAt()
method returns the character at a specified index in a string.
let str = "Hello, world!";
let char = str.charAt(1);
console.log(char); // Output: "e"