In JavaScript, the Strings object provides a number of methods for working with strings.
Here are some commonly used methods:
length: returns the length of the string
const myString = "hello world";
console.log(myString.length); // 11
toUpperCase(): returns the string in all uppercase
const myString = "hello world";
console.log(myString.toUpperCase()); // "HELLO WORLD"
toLowerCase(): returns the string in all lowercase
const myString = "HELLO WORLD";
console.log(myString.toLowerCase()); // "hello world"
charAt(): returns the character at a specific index in the string
const myString = "hello world";
console.log(myString.charAt(1)); // "e"
substring(): returns a portion of the string based on start and end indices
const myString = "hello world";
console.log(myString.substring(0, 5)); // "hello"
split(): splits the string into an array based on a delimiter
const myString = "hello,world";
console.log(myString.split(",")); // ["hello", "world"]
indexOf(): returns the index of the first occurrence of a specific substring in the string
const myString = "hello world";
console.log(myString.indexOf("world")); // 6
These are just a few examples of the methods available in the Strings object. There are many more methods available for working with strings in JavaScript.
