Common String Methods
The following string methods do not mutate the existing string.
str.endsWith(searchString)
– returns (boolean), determines if a string ends with a searchString.
str.startsWith(searchString)
– returns (boolean), determines if a string starts with a searchString.
str.includes(searchString)
– returns (boolean), returns true if string includes searchString anywhere within it.
str.indexOf(searchString)
– returns the first occurrence of the searchString or -1
if none found.
str.lastIndexOf
– returns the last occurrence of the searchString or -1
if none found.
str.match(regexp)
– returns the array of the first match of a regular expression.
str.search(regexp)
– returns the index of the first match or -1
if not found.
str.replace(regexp|substr, newSubstr|function)
– replaces occurrences that match either a string or a regular expression with a new string. Can also be passed a function that creates the new replacement string.
str.slice(beginIndex[, endIndex])
– returns a new string from beginIndex to endIndex.
str.split([separator[, limit]])
– returns an array or strings.
str.substr(start[, length])
– returns new string from the start index and of specified length or to the end if none provided.
trim()
– returns a new string with whitespace (space, tab, no-break space, etc.) removed from both ends.
str.toUpperCase()
– returns a new string with uppercases - might not work with all unicode chars.
str.toLowerCase()
– returns a new string with lowercases - might not work with all unicode chars.
fromCharCode
– returns a new string consisting of the characters represented from the Unicode.
normalize([form])
– returns new string of the normalized type.
Next Article: Arrays