The following methods are some of the most commonly used methods when working with strings.
Most string methods do NOT a change the original string, but instead return a new altered string.
toLowerCase() / toUpperCase()
toUpperCase(). Like most string methods, these methods do not change the original string.
const greeting = 'Hello, World!' // converting the letters to lowercase console.log(greeting.toLowerCase()) // 'hello, world!' // converting the letters to uppercase console.log(greeting.toUpperCase()) // 'HELLO, WORLD!' // The original string is unchanged console.log(greeting) // 'Hello, World!'
split() method splits a string into an array of strings, by separating the string on a specified separator.
const command = "Take me to your leader!" // splitting the string at each space console.log(command.split(' ')) // ['Take', 'me', 'to', 'your', 'leader!']