String Methods in JS

string methods = allow you to manipulate and work with text (strings)

let username = "BroCode";
 
//.charAt()
console.log(username.charAt(0)); //get the character at index 0, the output should be "B"
 
//.indexOf()
console.log(username.indexOf("o")); // get the first occurrence index of the letter "o", the output should be "2"
 
//.lastIndexOf()
console.log(username.lastIndexOf("o")); //get the last occurrence index of the letter "o", the output should be "4"
 
//.length
console.log(username.length); //how many characters, the output should be "7"
 
//.trim()
username = username.trim(); //here can trim any white space
console.log(username);
 
//.toUpperCase() .toLowerCase()
username = username.toUpperCase();
console.log(username);
 
//.repeat()
username = username.repeat(3); //here should repeat 3 times
console.log(username);
 
//.startsWith() .endsWith() .includes()
let result = username.startsWith(" "); //check if the string starts with a space
console.log(result); //output a boolean, true/false
 
//.replaceAll()
let phoneNumber = "123-456-7890";
phoneNumber = phoneNumber.replaceAll("-", ""); //replace all "-" with no character
console.log(phoneNumber); //1234567890