JS STRING METHODS Flashcards
Trim
.trim ()
Removes empty/white space before the start and after end of content in a string
Uppercase and Lowercase
text.toUpperCase()
text.toLowerCase()
(Changes the text to upper or lowercase)
Index Of
.indexOf (argument)
(Returns the index position)
// NOTE: indexOf will always return the first occurrence of the argument
Replace
.replace (argument)
(Replace content in a string)
// The first argument is the character(s) being selected. The second argument is the character(s) that is replacing the first.
Repeat
.repeat (argument)
Repeats content in a string
Slice
.slice (argument)
(Extracts part of string)
// First number/argument is the starting index. Second number/argument is the ending index (NOTE: Goes up to the second number/index, but does NOT include it in the slice).
//If a second number is NOT included, then the rest of the string will be included in the slice.
// When using negative numbers it starts from the end of the string (Starting at 1 NOT 0)